Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: catching double keyboard presses exception

  1. #1
    Guest

    catching double keyboard presses exception

    Hi,

    When I press too fast on my keyboard, my OpenGL program crashes.

    I think that my program registers that there are 2 keys being inputed at one time and therefore crashed.

    How do I solve this problem???

    Thanks.

    My keyboard codes:

    KeyPressed (...)
    {
    switch(case):
    {1: rotateY -= 10.0f;
    break;
    default: break;
    }
    glutPostRedisplay();
    }

  2. #2
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Computer Graphics Group, RWTH Aachen, Germany
    Posts
    137

    Re: catching double keyboard presses exception

    Hi
    try this:
    KeyPressed()
    {
    static bool sbProcessingKey = false;
    if (sbProcessingKey)
    {
    return;
    }
    sbProcessingKey = true;

    ////write here your keys handling code
    sbProcessingKey = false;
    }
    If this doesn't help, I suggest you to debug your program more, and to find really where it crashes...

    Regards
    Martin

    [This message has been edited by martin_marinov (edited 04-16-2002).]

  3. #3
    Guest

    Re: catching double keyboard presses exception

    hi martin,

    I do not understand why your code can solve my problem,

    can you roughly explain?? thanks a lot!

  4. #4
    Guest

    Re: catching double keyboard presses exception

    hi martin,

    I do not understand why your code can solve my problem,

    can you roughly explain?? thanks a lot!

  5. #5
    Guest

    Re: catching double keyboard presses exception

    hi martin,

    I do not understand why your code is able to solve my problem...

    can you roughly explain???

    Thanks a lot!

  6. #6
    Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Vancouver BC Canada
    Posts
    433

    Re: catching double keyboard presses exception

    Martin's code, roughly speaking, prevents the function from re-entering itself.

    Anyways, I doubt it will help. You need to post a lot more info if you want help. Like, where EXACTLY is it crashing? (Hint: you need a debugger to know this). What is the code doing there? etc etc etc

  7. #7
    Guest

    Re: catching double keyboard presses exception

    My keypressed function:

    void keyboard ( unsigned char key, int x, int y )
    {
    switch ( key ) {
    case 'z':
    scale += 10.0f;
    break; // Ready For Next Case
    default: // Now Wrap It Up
    break;
    }
    }

    I couldnt use my debugger on my program. Somehow it runs through my glut codes without going into the function.

    However, my program have a tendency to crash whenever I pressed on 'z' too fast. I think the system registers double clicks instead and hence is unable to function normally.

    Therefore, I am hoping that someone have caught this exception before and can help me.

    will try out the codes martin posted =)

  8. #8
    Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Vancouver BC Canada
    Posts
    433

    Re: catching double keyboard presses exception

    Originally posted by muzz:

    I couldnt use my debugger on my program.
    Uhm... why not?

    $ gdb <name of program>
    (gdb) run
    ... press 'z' a bunch of times and note where it crashes. Type 'bt' for a stack trace. Type 'list' for a listing of code.

    You know how to use gdb, right?

    Somehow it runs through my glut codes without going into the function.
    What does this mean, exactly? How do you know this? If it doesn't go in to your function, how can your function be to blame?


    However, my program have a tendency to crash whenever I pressed on 'z' too fast.
    Again, you've given way too little info for anyone to give you any meaningful help.

    I think the system registers double clicks instead and hence is unable to function normally.
    Or it could be phase of the moon isn't quite right... seriously, anything is possible with the very little info that you've presented.


    will try out the codes martin posted =)
    Good luck.

  9. #9
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Computer Graphics Group, RWTH Aachen, Germany
    Posts
    137

    Re: catching double keyboard presses exception

    Hi
    muzz - try really to debug your program - my code may help (I doubt it will however), but it can hide something wrong somewhere in your code ...
    Learn to use a debuger - if not gdb, then the internal debuger of kdevelop. When you compile your program just use the -g switch of gcc and so on.

    We here really need more info to help you...

    Regards
    Martin

  10. #10
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    fu,ck,you
    Posts
    3

    Re: catching double keyboard presses exception

    hi martin,

    I do not understand why your code is able to solve my problem...

    can you roughly explain???

    Thanks a lot!

Posting Permissions

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