keyboard..

Currently I am using this for input…

void sinputevent(int key, int x, int y) {
objectype temp;
int move = 1;
switch (key) {
case GLUT_KEY_UP:
objects[0].y -= (pointscale * move);
break;
case GLUT_KEY_DOWN:
objects[0].y += (pointscale * move);
break;
case GLUT_KEY_LEFT:
objects[0].x -= (pointscale * move);
break;
case GLUT_KEY_RIGHT:
objects[0].x += (pointscale * move);
break;
}
glutPostRedisplay();
}

(note: I removed my routines to call collision detection to just show as an example here)

and it doesnt seem to let me push two keys at a time? any way around this?cause i need the guy to be able to walk diangly too (holding left and down for example)

[This message has been edited by method5 (edited 03-26-2002).]

Glut Keyb manager is just a simple utility wich is good for tutorials.

If you want full control on devices you must use assembly code or DirectInput wich is not discussed on OGL forums.

2 simple solutions (among many others)

  1. with glut. You maintain an array of bools (one for each key you use). It’s true for pressed and false else. You refresh it with glut’s keyboard func.
  2. with the win32 api : you just call GetAsyncKeyState, declared in winuser.h

Morglum

“1) with glut. You maintain an array of bools (one for each key you use). It’s true for pressed and false else. You refresh it with glut’s keyboard func.”

Could you give me an example please… :slight_smile:

using the special keys i mean… not the normal ones… (the up, down, right, ect.)

You can search this forum, someone posted an example last week. But honnestly, I prefer the 2nd method (GetAsyncKeyState). It reads any key at the moment you need it. In any case I don’t like to be dependent of any messaging system, because you never know how much time has elapsed between the moment the user presses the key and the moment windows sens you the message.

For GetAsyncKeyState, you don’t need any example – it’s so simple to use.
However here’s one :
if (GetAsyncKeyState (VK_UP))
{ // move upwards…
}
See ?

Note : GetAsyncKeyState still isn’t the ultimate way of reading the keyboard because if you’ve to read 50 keys each frame, it’s 50 API calls. I think that the best solution for gaming under windows is directinput.

Morglum