Detecting keypress outside the program windows?

Hello,

I am trying to make a keybind program, but in order for it to work, I have to check if a certain key is pressed while another window has the focus, and then simulate what the users has entered. I am successfully able to simulate keypress, but I cant manage to detect it outside the main window. Its a keybind program for the game Grand Theft Auto: San Andreas, so I could check if the name of the window contains "San Andreas", then check if a certain key is pressed while that last windows has the focus, it would be helpfull. Ive searched for ages on Google and MSDN, and I am not able to find anything. Help would be apreciated.

Thanks.



Answer this question

Detecting keypress outside the program windows?

  • Chris Honcoop

    Generally speaking, the window that has focus is where your events need to be. In your case you are attempting to read a keydown event in you popup window.

    So, put your keydown event in your pop up window, and have it call a method in your main window or better yet, create a keydown event class.

    I'm not sure what your code really looks like, but I imagine you will need to pass the sender and the KeyEventArg to your method...



  • Prashweenet

    Actually im trying to read key input in another window, and this window isnt mine... I wanna check if lets say "Key.D0" is pressed in the window that has in its title "San Andreas"... That might be a little complicated but a lot of people have done it (ok, in c++... maybe c# is not powerful enough or maybe some dll...)


  • Daudi

    Well thanks a lot, Im gonna take a look in these articles. I was already using win32 api to send keystroke to another windows.

    Alex.


  • craigman

    Hello, Alex

    It can be done in C++ by using win32 api, it's quite true.

    Also we can do it in C# by using win32 api, just interoperate with particular win32 api to get key.

    About platform invoke issue, you'd reference to: http://www.c-sharpcorner.com/UploadFile/shrijeetnair/win32api12062005005528AM/win32api.aspx

    http://www.developerland.com/CSharpGeneral/General/146.aspx

    Thanks



  • Detecting keypress outside the program windows?