Key handling in opengl, where?

Started by
4 comments, last by Tompa 20 years, 6 months ago
Where do you keep your keyhandling in an opengl windows program with KEYDOWN/UP calls? In WinMain or in the gl-code? Anywhere else?
Advertisement
You can use WM_MESSAGE to handle keys; I prefer to check key directly so you can easily manage multiple keys

bool IsKeyPressed(int virtualkeycode){ // check bit 15 return((GetKeyState(virtualkeycode)&(1<<15))!=0);}


virtualkeycode= VK_UP, VK_LEFT, VK_CONTROL,...(see VK_ on your reference...)
I have a separate class for that. The WndProc function receives the messages from Windows, of course, and stores the state changes in my input class. I have pointers to that input object where ever I might need to use it.
-Ostsol
I use two methods. One is a simple message type, the other is just at the start of my rendering code.

bascially
onidle=renderingfunc

then the rendering func consists of bascially
getasynckeystate()
updatepositions(time)
renderdisplay()

I prefer getasynckeystate as opposed to the key messages, but either does the trick well (just depends on how you lay out the program)
Beer - the love catalystgood ol' homepage
If you want to use WM_MESSAGE you should keep track of your keyboard state by toggling a bit flag

Something like this

KEY_DOWN -> bPressed(key) = TRUE
KEY_UP -> bPressed(key) = FALSE

Thanks for helping me out!
I think I have got a bit wiser now.

This topic is closed to new replies.

Advertisement