Reputation: 12772
Using OpenGL /GLUT how would I detect if two keys, say 'a' and 'j' are held down at the same time?
(This program needs to compile with OSX GCC, Windows GCC, Windows VS2005 so no OS dependent hacks please.)
Upvotes: 13
Views: 10388
Reputation: 27
by "nicer alternative" if you mean simpler and glut-independant input function then got with GetAsyncKeyState function...
MSDN - GetAsyncKeyState function
Upvotes: 0
Reputation: 6437
Try the following:
glutIgnoreKeyRepeat
to only get physical keydown/keyup eventsglutKeyboardFunc
to register a callback listening to keydown events.glutKeyboardUpFunc
to register a callback listening to keyup events.bool keystates[256]
array to store the state of the keyboard keys.keystates[key] = true
.keystates[key] = false
.(keystates['a'] || keystates['A']) && (keystates['j'] || keystates['J'])
.Look in that direction. Although I haven't tested it, it should work. You might also need glutSpecialFunc
and glutSpecialUpFunc
to receive messages for 'special' keys.
Also, be aware that GLUT is really old stuff and that there are much nicer alternatives.
Upvotes: 21