• Advertisement

Archived

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

Glut and key input.

This topic is 5947 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

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/

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement