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 get turing to recognize successive button pressed
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
born130




PostPosted: Thu Jun 26, 2003 2:53 pm   Post subject: How do you get turing to recognize successive button pressed

Hello,

My question is how do you get Turing to recognize several buttons pressed in succession?

for example: i am making a game that wants you to press say "left arrow, right arrow, left arrow, left arrow" in succession inorder to do a combo move.

any help is appreciated

Thanks
Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Thu Jun 26, 2003 2:57 pm   Post subject: (No subject)

could use getch and have a key buffer, then calculate the amount of time it takes between each input, if the time is over certain level, then take a character away from the buffer.

anyways, I believe there is a topic on this already, so y don;t u search the help forum.
Homer_simpson




PostPosted: Thu Jun 26, 2003 3:03 pm   Post subject: (No subject)

most keyboards dont detect more than 4 keys at once... u can use getch but it's pretty slow =/
Andy




PostPosted: Thu Jun 26, 2003 3:57 pm   Post subject: (No subject)

born130 what u need is an array from 1 to how many keys you want to be pressed read my tutorial on arrays if u dun know how to use them http://www.compsci.ca/bbs/viewtopic.php?t=1117
ok you want the array to be integers containing the ascii number of the keys you want so have something like this
code:

var keystroke:array 1..count of int


now all you need to do is have a loop and go
in the following code counter is which key ur currently at
if the user messes up, the counter resets to 0. count is the number of keys the user needs to end the program
code:

counter:=1
loop
exit when counter=count
if hasch(ch) then
getch(ch)
if ord(ch)=keys(counter) then %keys is the array with all the ascii numbers
counter+=1
else
counter:=0
end if
end loop
born130




PostPosted: Thu Jun 26, 2003 4:26 pm   Post subject: (No subject)

So how do I put the keys in to be recognized?
i.e. how do i declare which keys to be pressed in the right order


code:
var counter, count : int
var ch : string
var keystroke : array 1 .. 10 of int
counter := 1
ch := "a" + "b" + "c"
loop
    exit when counter = count
    if hasch (ch) then
        getch (ch)
        if ord (ch) = keystroke (counter) then %keys is the array with all the ascii numbers
            counter += 1
        else
            counter := 0
        end if
    end loop
Andy




PostPosted: Thu Jun 26, 2003 4:29 pm   Post subject: (No subject)

no no no
okay lets say there are 3 keys, you juss go
keystroke(1):=ord("a")
keystroke(2):=ord("b")
keystroke(3):=ord("c")
born130




PostPosted: Thu Jun 26, 2003 4:48 pm   Post subject: (No subject)

code:

var keystroke : array 1 .. 5 of int
var counter : int
var count := 3
keystroke (1) := ord ("a")
keystroke (2) := ord ("b")
keystroke (3) := ord ("c")
var ch : string
ch : = keystroke (1)
counter := 1
loop
    exit when counter = count
    if hasch (ch) then
        getch (ch)
        if ord (ch) = keys (counter) then %keys is the array with all the ascii numbers
            counter += 1
        else
            counter := 0
        end if
    end loop

so my question was how do i get them to recognize the buttons pressed

second question is does this code only work for the buttons pressed simutaneously?

because my goal is for it to be pressed succesively

i.e. press "a" then "b" then "c" ...etc.
Andy




PostPosted: Thu Jun 26, 2003 6:00 pm   Post subject: (No subject)

no born130, this code only works for buttons pressed one after another...
y do you have the array to size 5 when you only need 3 buttons? just change the
keystroke (1) := ord ("a")
keystroke (2) := ord ("b")
keystroke (3) := ord ("c")

keystroke(1) is the first input
(2) is the second and so on

the buttons are inside the ord()
Sponsor
Sponsor
Sponsor
sponsor
PaddyLong




PostPosted: Thu Jun 26, 2003 6:05 pm   Post subject: (No subject)

here is an explanation.... hopefully this clears up how it works for you born

this section of code declares the keys that are to be pressed (in this case, it would be that it is expecting the user to press a, then b, then c)
code:

var count := 3
var keystroke : array 1 .. count of int
keystroke (1) := ord ("a")
keystroke (2) := ord ("b")
keystroke (3) := ord ("c")


the counter keeps track of how far into the progression of key strokes the user is.. so which index of keystroke it is expecting next
code:

var counter : int := 1


code:

var ch : string (1)

loop
    if hasch then     %if a key has been pressed
        getch (ch) %get what key it was
        if ord (ch) = keystroke (counter) then
            %if the key that was pressed matches the key at the current index of the progression then move on to the next index (add one to counter)
            counter += 1
        else
            %if it was not the next key that should have been pressed, reset the current index of the progression to the start
            counter := 1
        end if
        exit when counter > count %leave the loop when it reaches the end of the progression (ie the user has pressed all the keys in the correct order)
    end if
end loop
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  [ 9 Posts ]
Jump to:   


Style:  
Search: