View Full Version : How do I handle Keyboard events, using Window`s proc or DirectInput?
I want to be able to know if there are 2,3 or more keys pressed at a time...
10-11-2000, 03:13 PM
You have to catch the appropriate message... I don't rebember it well, it seems to me WM_KEYDOWN. Then you set a flag in a boolean array representing all the keys (or the keys you use). When you catch the other win msg WM_KEYUP you have to clear the flag, simply.
I did it, it worked.
Sorry I can't post the code, I'm not on my pc.
10-11-2000, 03:45 PM
You can get the keys by processing the WM_KEYDOWN and WM_KEYUP messages, but be aware that method can suffer from significant latentcy and also requires dealing with multiple WM_KEYDOWNS due to auto key repeating. You are better off simply using, for every frame, GetAsyncKeyState for each key you want to monitor. Or if you use DirectInput, you can configure a keystate buffer, and with a single function call, update the keystate buffer with the current key states. This can be much faster than issuing multiple GetAsyncKeyState calls when you have lots of keys to handle.
[This message has been edited by DFrey (edited 10-11-2000).]
10-11-2000, 05:30 PM
If you can afford the time then you should have a go at DirectInput. It is faster and it doesn't restrict the mouse to the screen, i.e. you can keep scrolling to a side indefinetely.
I've done an example but its not presentable, if you want it anyway just e-mail me.
Meanwhile, there is a tutorial on DirectInput by Justin Eslinger at http://nehe.gamedev.net/tutorials/lesson23.asp
Antonio www.fatech.com/tech (http://www.fatech.com/tech)
Thanks Antonio...That is what I was looking for in my Keyboard posting Earlier regarding Keyboard Key Codes in VC++! http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif
You can keep scrolling indefinitely using the mouse without DirectInput...
I am using MFC and OpenGL to build professional applications and one of my programs (a 3D Modeller) uses this to rotate objects (it is frustrating if the rotation stops coz' you hit the border of the screen !).
You basically have to check where your mouse is when it is moving (WM_MOUSEMOVE or OnMouseMove) and if it is hitting one of the border, you just set the mouse cursor on the opposite border....
That's easy, isn't it ?!?!???
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.