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,978

    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 << | key];

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

Similar Threads

  1. Ctrl size changed when im changing the resolution
    By pnpvivek in forum OpenGL: Windows
    Replies: 0
    Last Post: 10-29-2009, 09:44 AM
  2. Picking, ctrl pts on nurbs surface
    By JamesH in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 12-16-2007, 12:40 PM
  3. checking for ctrl key input
    By cubbie in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 10-10-2002, 03:39 AM
  4. GLUT - Shift key?
    By stratos in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-14-2002, 01:25 AM
  5. how to disable Ctrl + Alt + Del
    By ZeeBoy in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 02-28-2001, 01:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean