GetAsyncKeyState is global, even if my application is minimized, it will check for key input. Is there any way of doing it for a single application?
GetAsyncKeyState is global, even if my application is minimized, it will check for key input. Is there any way of doing it for a single application?
You could either check for input with GetAsyncKeyState only if your window is active, or you could just use Windows messages which does that for you. It all depends on what you're making.
I'm making a game, i need a key input system for a console based application.
There's a way of hooking async with one program...but how to?
As far as I know, no. I would try my first idea. Just check if your window is active using IsWindowEnabled, and if it is then check for input with GetAsyncKeyState.
Edit: This probably also belongs in Windows...
Microsoft now recommends raw input over DirectInput. There probably are alternative, more portable game input libraries available though. Check into SDL, although I recommend SFML.
Moved to Windows Programming forum.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Code:if(GetAsyncKeyState(key) && GetFocus()==yourhwnd){ handle the input }
Last edited by maxorator; 11-09-2008 at 02:19 AM.
"The Internet treats censorship as damage and routes around it." - John Gilmore
Since you will be using this in a game, you will go into your GetAsyncKeyState loop, so first you wanna check the GetFocus() == yourhwnd, and then go into your key waiting loop.
★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★
Just don't burn out the CPU. Check if the key was pressed down (or up) since the last call. It is a semi-buffered API, but it is better than nothing.
Although better would be to use a real buffered API such as that DirectInput & probably other input API offers.