Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: CTRL, ALT and SHIFT key in GLUT

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2000
    Location
    Hong Kong
    Posts
    9

    CTRL, ALT and SHIFT key in GLUT

    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.

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2000
    Location
    New Jersey, USA
    Posts
    23

    Re: CTRL, ALT and SHIFT key in GLUT

    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

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2000
    Location
    Hong Kong
    Posts
    9

    Re: CTRL, ALT and SHIFT key in GLUT

    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.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,982

    Re: CTRL, ALT and SHIFT key in GLUT

    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...

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2000
    Location
    New Jersey, USA
    Posts
    23

    Re: CTRL, ALT and SHIFT key in GLUT

    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;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •