Simulating keypresses?
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
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!
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!
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 );}
(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
Thanks, Mr Crypter and Mr Spurious! I'll start learning these right away, they're quite advanced for me.
Thanks again! ^_^
-regards,
BlueBolt
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement