How do you make the program do something on any keyboard button press *other* than a certain letter?
Author |
Message |
PersonalPinky
|
Posted: Thu Feb 05, 2015 10:39 pm Post subject: How do you make the program do something on any keyboard button press *other* than a certain letter? |
|
|
Basically, I want a program that does a procedure when q, w, e are pressed but when any other button is pressed it does something else. However, it does not work because right now it just keeps calling procedure4 even when I do not press any buttons. Is there any way to call procedure4 on a button press other than q, w and e? Here is an excerpt from my code:
Turing: |
loop
Input.KeyDown (key )
if key ('w') then
procedure1
exit
elsif key ('e') then
procedure2
exit
elsif key ('q') then
procedure3
exit
else
procedure4
exit
end if
loop
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Thu Feb 05, 2015 10:53 pm Post subject: RE:How do you make the program do something on any keyboard button press *other* than a certain letter? |
|
|
Well that's because you're not checking if any key is being pressed, just that w, e, or q is not pressed.
Try iterating every single value for the key array like so. The char keyword is fucking weird as it can be expressed as a range as well as a data type (which makes sense if you uderstand what a char is).
Turing: |
View.Set ("text")
var chars : array char of boolean
Input.KeyDown (chars )
for c : char
put c, " ", chars (c )
end for
|
This way you can check if each key is pressed, then run the procedure. Don't forget to exit the loop on the first key you find pressed with continue. |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Thu Feb 05, 2015 11:36 pm Post subject: RE:How do you make the program do something on any keyboard button press *other* than a certain letter? |
|
|
Alternatively, you could use the hasch() keyword, though you may run into strange glitches when someone presses a key during the split-second between the Input.Keydown call and the hasch() call without some clever placement. |
|
|
|
|
![](images/spacer.gif) |
|
|