Thread: Keyboard question with allegro

  1. #1
    Registered User Ion Blade's Avatar
    Join Date
    May 2002
    Posts
    35

    Keyboard question with allegro

    Hi..

    my problem is with keyboard input using allegro. what i'm trying to do is fairly simple...i have a Status indicator box that you can toggle on and off. right now i have it set up so that pressing the S key will toggle it. i have the function that toggles the box tied to a timer that will call it every 125 milliseconds. now is where my problem comes in.

    the user has to press S at just the right time for the box to come up, or hold it and then let go very quickly so it won't turn off the instant it turns on. how can i make it so the user has to press S once to turn it on, and let go of the key and fully press it again to turn it off?
    "Im going to have peaceful dreams of brackets and semicolons strapped on crucifixes, screaming for mercy" - Someone who doesn't like programming.

  2. #2
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Allegro is very touchy when it comes to having the same key being on/off. Try clearing the keybuffer
    ( clear_keybuf() ) after each time a key is pressed then initialize a small delay; this might solve your problem.

  3. #3
    Registered User Ion Blade's Avatar
    Join Date
    May 2002
    Posts
    35
    ah i figured it out. here's an example of what i did (just for reference heh) :

    Code:
    bool S_IS_DOWN = false;
    
    void GetInput()
    {
      if (key[KEY_S] & !S_IS_DOWN)
      {
         S_IS_DOWN = true;
         
         HappyFunction();
         // do stuff
       }
    }
    
    int main()
    {
      while (running)
      {
        if (!key[KEY_S])
          S_IS_DOWN=false;
        else
          S_IS_DOWN=true;
    
    
         GetInput();
         OtherStuff();
    }
    with this code, the user will have to let go of S and press it again for the function HappyFunction() to happen again.
    "Im going to have peaceful dreams of brackets and semicolons strapped on crucifixes, screaming for mercy" - Someone who doesn't like programming.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. double buffering for allegro
    By Leeman_s in forum C++ Programming
    Replies: 6
    Last Post: 09-12-2002, 02:45 PM
  2. quick allegro question
    By Leeman_s in forum C++ Programming
    Replies: 1
    Last Post: 09-10-2002, 01:46 PM
  3. Quick Allegro Question
    By kas2002 in forum Game Programming
    Replies: 15
    Last Post: 08-09-2002, 06:07 PM
  4. ALLEGRO Question
    By Unregistered in forum Game Programming
    Replies: 10
    Last Post: 10-22-2001, 01:27 PM
  5. ALLEGRO Question
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 09-14-2001, 11:06 AM