Glut and key input.

Started by
1 comment, last by laeuchli 22 years, 6 months ago
Hey, I''m writing a game(www.laeuchli.com/jesse/), where you fly a spaceship around and shoot. I''m using GLUT and OpenGL. The problem is, that I can''t press more then one button at a time. For example, the down arrow pulls the plane up, and the right arrow makes the plane go right, and they both work sepratly, but when I try to do both at once, only one takes. This is annoying, and I need to find a way to fix it. How should I do it with glut? Thanks, Jesse www.laeuchli.com/jesse/
Advertisement
One way you could do it is have an array of booleans (one for each key) eg declared like this:

bool keyDown[NUM_KEYS];

... and when a key is pressed, set its keyDown to be true (and inversely, when a key is released, set it to false).

Then, somewhere else (perhaps in an idle func or timer func), you check what keys are down at that given moment, and move your ship accordingly.

Simple, eh?


EDIT: you may also want to suppress key repeats (no point processing multiple keydown events)... but i can't remember how to do it off the top of my head... check the glut docs

Edited by - Bad Monkey on October 8, 2001 10:42:31 PM


EDIT (again): I just checked the docs myself, and it seems that my rusty memory has failed me again... there doesn't seem to be a way to determine when a key is released (only pressed). Must've been thinking about mouse buttons ...sorry about that

Edited by - Bad Monkey on October 9, 2001 9:40:51 AM
Hey wow thanks. I`ve been wondering about that myself.
I havnt done any work with it though, so thanks.
~V''lion

I came, I saw, I got programmers block.
~V''''lion
~V'lionBugle4d

This topic is closed to new replies.

Advertisement