Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How do you make the program do something on any keyboard button press *other* than a certain letter?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
PersonalPinky




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: 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.
Insectoid




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: