Sign in to follow this  
BlueBolt

Unity Simulating keypresses?

Recommended Posts

BlueBolt    100
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
Crypter    748
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
BlueBolt    100
(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
speedie    140
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this