tags:

views:

298

answers:

2

This is a similar problem: Link
Which was solved by calling GetAsyncKeyState(). While all fine and dandy, I need a Linux alternative. I need to know if a button is being held down, not just being pressed (because of the keyboard buffer delay).

Does anything like this exist in the OpenGL/Glut libraries, or will I have to look elsewhere?

A: 

You can detect when a keypress event occurs, record that state, and then listen for a key release event.

Scottie T
Which is what I am (sort of) currently doing. The problem is, glutKeyboardFunc() doesn't pass the current state. It only passes the ASCII character of the key.
Wally
So keep track of the button you're interested in. You'll have to roll your own button state machine.
Scottie T
+2  A: 

I have never used Glut, but I know that many people will say SDL is better. I have used SDL and I like it a lot. It does everything Glut does and a lot more. In SDL, you can use SDL_PollEvent() to get key state without the keyboard buffer delay.

Edit: I know almost nothing about Glut, but it looks like you can use glutKeyboardFunc to detect normal keys, and glutSpecialFunc for keys that do not generate ASCII characters (such as shift). I'm not sure if there is a better way, as this doesn't seem very nice.

Zifre
Looks like this is what I'm going to have to do. SDL will fix other numerous problems as well. Thanks!
Wally