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.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With