PDA

View Full Version : Glut SpecialKeyFunc



dabeav
08-23-2002, 04:46 AM
If glut special key func takes care of keys like up arrow, down arrow, etc; How come I couldnt simply use the normal glut keyboard func, with the ASCII codes for up arrow, down arrow etc; Or is that function not able to handle any of those??

os instead of
void SpecialKeyboard (int key, int x, int y)
{
if(KeyHit == GLUT_KEY_LEFT)
{
DO SOMETHING
}
}

i would have
void NormalKeyBoard (int key, int x, int y)
{
if(KeyHit == 75)
{
do something
}
}

[This message has been edited by dabeav (edited 08-23-2002).]

nexusone
08-23-2002, 05:09 AM
I think the reason is that the arrow key's do not produce ASCII codes when pressed.



Originally posted by dabeav:
If glut special key func takes care of keys like up arrow, down arrow, etc; How come I couldnt simply use the normal glut keyboard func, with the ASCII codes for up arrow, down arrow etc; Or is that function not able to handle any of those??

os instead of
void SpecialKeyboard (int key, int x, int y)
{
if(KeyHit == GLUT_KEY_LEFT)
{
DO SOMETHING
}
}

i would have
void NormalKeyBoard (int key, int x, int y)
{
if(KeyHit == 75)
{
do something
}
}

[This message has been edited by dabeav (edited 08-23-2002).]

Deiussum
08-23-2002, 06:01 AM
Yes, the arrow keys the Fn keys, and some of the others produce extended codes.

If you were to do a simple app like so...




#include <stdio.h>
#include <conio.h>

int main(int argc, char* argv[])
{
char ch;

while(true)
{
if (_kbhit())
{
ch = getch();

printf("%i\n", ch);
}
}

return 0;
}


You will notice that the arrow keys produce not 1, but 2 characters.

dabeav
08-23-2002, 06:42 AM
ok, so when i build my Normal key board maping i do this.
bool KeyDown[256];
then when a key is pressed i set it equal to one.

KeyDown[key] = 1;

And i simply test to see if any of the keys are pressed each frame by check to see if they are true or not, so i can get around the limitations of GLUTS call back method. But if i want to use the Special keys function in the same method. How large would would I set that array. Like if i wanted to set the Left key in a bool table.

CODE:

void SpecialKeyPress(int key, int x, int y)
{
SpecialKeyDown[key] = 1;
}

Then i check to see if SpecialKeyDown[GLUT_KEY_LEFT] == 1;

But im not sure how large to create my
bool SpecialKeyDown[]; array. Im not sure how LARGE of an integer the special keys can be, anyone know?

Deiussum
08-25-2002, 10:36 AM
If I understand you right, I think you'd have to check the value of those constants in glut.h. You might also need to make sure that there is no overlap between constants that can be used in the normal keyboard function and the special keyboard function.