Win32 - GetKeyboardState vs GetAsyncKeyState

Started by
4 comments, last by theOcelot 14 years, 1 month ago
Whats the best way to handle keyboard input for games? Getting the state of all the keys every frame, and so checking witch ones you want to see if it is pressed, or, get the state of all the keys you want to check one by one ? I cant see much difference..in both you will have to do a specific key by key check, the get Keyboardstate seems less efficient since you never will need all the keys checked, but is just one function call... Maybe the best way is really on the performance of each function?? What do you know about it?
Advertisement
Why test for all keys? Just send function calls for the keys involved in your game :S
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
If you're keyboard code is soaking all your CPU time then you're game is too small to be worth optimising or you are doing something terribly wrong. Don't waste your time optimising something unless you have proof it is a bottleneck.

Personally, I prefer having a high level event system, I only care when keys are pressed or released, not about the current state of the keyboard.
Its not a question about optimization...I just have 2 almost the same option, I have to choose one, if theres any performance difference, why would I use the worse one?
You should probably just handle the WM_KEYUP and WM_KEYDOWN messages, that way you don't need to do any work unless a key has been pressed.
Well, if he needs the current state, not events, then all he would do with key-up/down messages is maintain his own state array, which is a silly redundance. It might even be slower. :D

This topic is closed to new replies.

Advertisement