Archived

This topic is now archived and is closed to further replies.

array of 256 keys?

This topic is 5015 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone here use the technique like Nehe does, where you keep an array of 256 boolean values representing whether the keys are down? I tried doing it but I ran into a problem. I use f as my forward key, so I have a test like this in my update function : const char FORWARD = ''f''; ... if (keys[FORWARD]) //move forward But it didnt work. Apparently its because keys[''f''] looks in keys[70], however actually pressing f sets keys[102]. Where the heck did 102 come from? How can I reliably set my movement keys without having to run the program and test which value actually gets set when I press it?

Share this post


Link to post
Share on other sites
Hmm no I didnt think i was dumb enough to have had the caps lock on without noticing. No matter what version of ''f'' I push (caps or no), it still gives code 102. Should I just assume that all letters have to be caps? this is kind of dumb. What if for some reason you wanted lower case letters input into a program?

Share this post


Link to post
Share on other sites
Well, not sure why it''s not working for you. If you''re checking in keys[''f''], then it should be looking in keys[102] which should work.

If you want the program to distinguish between upper and lower case letters, then you might have to check the Shift and Caps Lock keys yourself. I think I remember having to do that once.

Share this post


Link to post
Share on other sites
quote:
Original post by pinacolada
Well, not sure why it''s not working for you. If you''re checking in keys[''f''], then it should be looking in keys[102] which should work.

If you want the program to distinguish between upper and lower case letters, then you might have to check the Shift and Caps Lock keys yourself. I think I remember having to do that once.


OOOOOOOOOh. I didn''t know that. Ok thanks!

Although, you would think that it would be the other way around; lower case by default, and you need to check for shift or Caps to make them upper case.

Oh well.

Share this post


Link to post
Share on other sites
windows.... pffffff...

they have VK_LEFT, VK_RIGHT, ect... for keycode entries, but no VK_F, VK_U, VK_C, VK_K, which would clear the confusion.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
f and F are the same key on your keyboard (I''m assuming, they are on mine). What''s the confusion?

Assuming you are using Windows, look in WINUSER.H for the entire list of keyboard key constants.

If you are using DirectInput you should look in INPUT.H for the DirectInput equivalents (the numbers will be the same even though the constants are different).

When you are processing that message you are processing a key state, NOT A CHARACTER. The f KEY was hit. If you meant the ''F'' CHARACTER you will need to check if the one of the shift keys is also down.

There is the WM_CHAR message that does distinguish between f and F as characters.

BTW, you can get the keyboard state without saving the array by using the command GetAsyncKeyState() for the keys you care about (Windows is storing this array for you anyways).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The GetAsyncKeyState() bypasses the windows message loop, and should therfor not be used (if not specific reasons for bypassing the message loop exists), since your application will detect keypresses even if the window isn''t active (i.e. when you alt-tab to some other window to write emails, answer IM or whatever)

Share this post


Link to post
Share on other sites