KeyPressed class...dumb thing to do?
I''m doing a RTS with chat, and i was debating how to handel key and mouse buttons being pressed. I need my keys to be bindable.
I''ve not worked much with WM_CHAR.
I was thinking of making a keypressed class that would check all keys 10-20 times a second (not every frame). The class would be made of of a ton of ints, each one representing a key. Value 0 if the key isnt pressed, 1 if pressed but wasnt pressed last check, 2 if held down, and 3 if let up and was down last check.
I can then have pointers for all shortcuts and what not pointing to what ever they are bound to.
The class would write to a file when pointers are chaged and read from it when first initalized.
Is this a good method or am doing too much work?
You can just handle it in your windows message function, and pass it to the right function to handle the keypress at that exact moment...
It''s unnecessary to create a whole class for it...
It''s unnecessary to create a whole class for it...
Hmm well if thats not often enough I can always do it at 40-framerate times a second.
I''m going to have to create a class any way for binding keys. I think ill try and mess around with WM_CHAR.
I''m going to have to create a class any way for binding keys. I think ill try and mess around with WM_CHAR.
You shouldnt have to do a class with key bindings. It does sound horribly ineffecient. Another idea is to go ahead and use the array of int for key identifiers (bindings) and then in the window messageing function, pass all keypresses to a seperate function that checks against that area for what key was pressed and handle it that way. Just make each array element linked to a certain command.
At least it sounds easier.
At least it sounds easier.
>Hmm well if thats not often enough I can always do it at 40->framerate times a second.
Or 80 times, 160 times, 500 times, 1000 times, .....
So much processing power to burn away? One rule: Never poll! Wait for messages and use them. Why don''t you want to use WM_CHAR? Where''s the problem with it?
Lyve
Or 80 times, 160 times, 500 times, 1000 times, .....
So much processing power to burn away? One rule: Never poll! Wait for messages and use them. Why don''t you want to use WM_CHAR? Where''s the problem with it?
Lyve
_____________________________________http://www.winmaze.de, a 3D shoot em up in OpenGL, nice graphics, multiplayer, chat rooms, a nice community, worth visiting! ;)http://www.spheretris.tk, an upcoming Tetrisphere clone for windows, a 3D tetris game on a sphere with powerful graphics for Geforce FX and similar graphics cards.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement