#### Archived

This topic is now archived and is closed to further replies.

# Getting keystrokes

## Recommended Posts

Russell    118
How can I get my program to detect keystrokes no matter which program is currently active? Will GetAsyncKeyState (or whatever it''s named) do this?

##### Share on other sites
Peon    276
Perhaps this is way out there, but when I do keystrokes I''ve been doing:

  while(true){ if (kbhit()) { choice = getch(); //get keypress }}[/source[Might be totally irrelevant, I dunno :)

##### Share on other sites
Oluseyi    2115
quote:
Original post by Peon
Perhaps this is way out there, but when I do keystrokes I''ve been doing:

That''s essentially DOS/Console-style input while Russell is concerned about Windows input.

Russell: Look into Spy++. I believe there''s some source or further information for it which would give you some good ideas.

I wanna work for Microsoft!

##### Share on other sites
To be able to get all keystrokes globally you''d have to write your own keyboard hook.

Try searching the MSDN for some samples of doing it.

It''s not hard at all, just watch out for return values and default functions.

There are other ways as well, but this is the easiest way to do it.

btw, if you DO use hooks, you will have to send out your DLL that hooks the keyboard to the end user as well. So keep that in mind.

Hope this helps...

##### Share on other sites
Xorcist    122
Russell, take a look at this post:

http://www.gamedev.net/community/forums/topic.asp?topic_id=65987

I have already offered my code to Crazemanx, but he never got back to me. You are more than welcome to take a look at it, and use it for whatever you like. It's a basic global scanhook. Just let me know and I'll post a download link for it.

P.S. And if you're not big on translating the code from Delphi to C/C++ the compiled DLL should still work fine.

Edited by - Xorcist on November 7, 2001 2:40:12 PM