View Full Version : CTRL, ALT and SHIFT key in GLUT

04-19-2000, 09:45 PM
Hi all,

I don't know how to detect and handle event while the key CTRL, ALT or SHIFT key is pressed by using GLUT.
Anyone can help? Sample code given would be greatly appreciated.

04-19-2000, 11:21 PM
You can retrieve modifier key states with glutGetModifiers(). Check out man-page for more info. The following return values apply:


If you need to find out left or right shift, you got to turn to native window API.

Ctrl plus characters are directly handled with the Key-function. Ctrl-A yield the key-code 1, etc.

/ plg

04-21-2000, 04:56 AM
Really thx for your help. Could u help me more?
Now, I can detect the CTRL-A for key code 1 and the following, but I still can't find the key code for ALT-A and SHIFT-A .....

Thx again.

04-21-2000, 12:26 PM
You can do this by setting a variable if ATL, CTRL or SHIFT is pressed, then when a key is pressed, you just check if either of the three keys is pressed.

Some pseudocode...

if ALT is pressed, alt=1, else alt=0
if ALT is pressed, crtl=1, else crtl=0

if 'a' is pressed and alt=1, alt_a is pressed
if 'a' is pressed and ctrl=1, alt_a is pressed
and so on...

04-24-2000, 01:35 AM
In your key-function or mouse-function, get the modifier states with glutGetModifiers(). Then go on in a way described by Bob, or build tables so you can map it to a code. A lot of ifs isn't the best way, switch is better.


states = glutGetModifiers();
action = lookupTable[(states << 8) | key];

switch (action) {
case A_ROLL: