Jump to content
  • Advertisement
Sign in to follow this  
BlueBolt

Unity Simulating keypresses?

This topic is 4069 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi to the entire GameDev community... I wondering if there is any method by which I can simulate keypresses in a C++ program? The program is intended for use on Win32 platform, although I'ld like to know the possibilities for other OSs too, if possible. -regards, BlueBolt

Share this post


Link to post
Share on other sites
Advertisement
One possible solution is with buffered input.

By storing the state of each key, you can have a GetKeyState
method to return the status of a key in the buffer.

Because the keys in the buffer or stored in the program, it is
very easy to modify the buffer (changing the status of a key)

Under Windows, you can use the GetKeyboardState to retrieve the current state of all keys,
and SetKeyState to set the programs keyboard state table directly.

You can also try SendInput

Hope this helps!

Share this post


Link to post
Share on other sites
the HWND is for the window you are trying to click in. mx and my are mouse positions in the windows geometry. this works for clicks in your program and for other programs you might want to sent clicks to.


void MouseClick( HWND hwnd, int mx, int my )
{
SetCursorPos( mx, my ); // needed for SUN JavaVM windows
Sleep( 10 ); // give time for cursor to move

LPARAM pt = my;

pt <<= 16;
pt += mx;

::PostMessage( hwnd, WM_LBUTTONDOWN, MK_LBUTTON, pt );

Sleep( 10 ); // time between mouse down and up

::PostMessage( hwnd, WM_LBUTTONUP, 0, pt );
}



Share this post


Link to post
Share on other sites
(O.O Wow, this is big league stuff! xD)
Thanks, Mr Crypter and Mr Spurious! I'll start learning these right away, they're quite advanced for me.
Thanks again! ^_^
-regards,
BlueBolt

Share this post


Link to post
Share on other sites
if youre looking to run somthing outside of the program that simulates input. take a look at AutoIt. it's a scripter that can read the screen and simulate mouse/keyboard input.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!