Skip to main content
gamedev.net
🔒 Locked

C# getting input

Started by Catkill Jun 28, 2010 at 7:47 AM 1 replies 1k views
Original Post
Catkill
Catkill
I have a program which will simulate mouse movement and presses, which is looped via a timer. my only problem is stopping the program as I cant click a stop button when the mouse is Hijacked. The mouse is clicking another window so the form doesnt have focus. How can I detect keyboard input to stop the timer?

Thanks
Blair
Adam_42
Adam_42
You could PInvoke GetAsyncKeyState(). Not sure if there's a nicer way of doing the same thing.
MJP
MJP
One thing you can do is register "hot keys", which are global key combinations (for example, ctrl + alt + shift + p) that are automatically detected by Windows. When the users presses the hot key combination, it sends your thread a message with an ID indicating which hot key was triggered. The nice thing about this is that hot keys have to be globally unique (so you can ensure that the key combination doesn't conflict with another app's controls), and it also doesn't require your app to constantly poll for keyboard input.

Doing it in C# is really easy. The pinvoke.net entry for RegisterHotKey has sample code that you can probably just drop in, and if you need more info then you can check out the MSDN docs.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.