Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problems with char conversions

Started by dnaxx Nov 1, 2005 at 3:35 AM 3 replies 350+ views
Original Post
dnaxx
dnaxx
Hello, I use a global array which stores the pressed keys:

bool g_key[255];
now, when a key is pressed the corresponding index in the array is set to true:

void special_keys(int a_keys, int x, int y)
{
 g_key[a_keys] = true;
}
This works fine, but e.g. these two keys have the same integer value:

GLUT_KEY_RIGHT == 102
(unsigned int)'f' == 102
So when I press one of these keys, both actions are executed :(. How can I fix this? Thank you,
ToohrVyk
ToohrVyk
GLUT_KEY_RIGHT represents a special key which is obtained through glutSpecialFunc. That function is not meant to detect key presses other than for special keys, and 'f' is not a special key, therefore you should not be able to detect presses of both GLUT_KEY_RIGHT and 'f' using the same mechanism.
dnaxx
dnaxx
ok. in other words: I should store special keys and "normal" characters in different arrays?
ToohrVyk
ToohrVyk
Or look for an API which allows you to store both in the same way.

Either way, the number of arrays you use to store the keys is irrelevant to the way you will check if a key is pressed, since you're a good designer and thought of isolating input logic from the rest of the code with well-named functions.
dnaxx
dnaxx
thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.