Shop OBEX P1 Docs P2 Docs Learn Events
Problem with PS/2 button detection routine — Parallax Forums

Problem with PS/2 button detection routine

RussMRussM Posts: 27
edited 2013-01-07 18:13 in Propeller 1
Hello everyone. I was hoping someone could help me with a program I am making that detects and prints out a message if the user presses a 1,2,3,4 or 5 on a ps/2 keyboard. The routine works (sort of). To get the "1" message to display the I need to hit the 1 key one time, to get the "2" message to display I need to hit the two key twice, the three key twice for "3", etc. I believe it has something to do with calling the function getkey 5 times, however I tried messing with the functions and whatnot and really haven't gotten anywhere. Would anyone have an idea why this isn't working? Any insight is greatly appreciated.

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-01-07 18:04
    The getkey method blocks (may wait for keypress). So I suggest you read the keyboard once at the beginning of the loop and then do the evaluation on the returned value.
    repeat
        c := kb.getkey
        ' evaluation using if/case/etc
        if c == '1'
          ...
    
    Also, calling a method from within itself is a really bad idea, eventually you'll run out of stack. As you are in a repeat construct you might as well use next.
  • RussMRussM Posts: 27
    edited 2013-01-07 18:13
    Thank you for your help! The code format you provided worked perfectly.
Sign In or Register to comment.