Hello,
I’m trying to write a code that tests if one of several specific letters was pressed on the keyboard and pending on that, does one of two things. Sounds simple, I know, but I’m having problems with this as specified:
The following example should define that cor=1 if ‘a’, ‘b’, ‘c’, or ‘d’ were pressed, and that cor=0 if any other key was pressed. However, while a single press on the ‘a’ key does produce cor=1, several presses on any other key are required in order for the code to proceed (and then the cor is correctly defined). I don’t understand why this is the case and couldn’t solve it. Any help will be appreciated!
Note that this is just an example and that in the final code this operation should be applied multiple times on different letters each time.
letters=[‘a’ ‘b’ ‘c’ ‘d’]
FlushEvents(‘Down’)
KeyIsDown=0;
[KeyIsDown,secs,KeyCode] = KbCheck;
while 1
if KeyIsDown
if KbName==letters(1) || KbName==letters(2)
cor=1;
break;
else
cor=0;
break;
end
end
end
return
Thank you,
Roy Shoval