PDA

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



SiuBanana
04-19-2000, 08: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.
Thx.

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

GLUT_ACTIVE_SHIFT, GLUT_ACTIVE_CTRL, GLUT_ACTIVE_ALT.

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

SiuBanana
04-21-2000, 03: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.

Bob
04-21-2000, 11:26 AM
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...

plg
04-24-2000, 12: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.

e.g.

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

switch (action) {
case A_ROLL:
......
......
default:
error();
break;
}