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

Username:   Password: 
 RegisterRegister   
 loops - exit when a key is entered?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
florayu




PostPosted: Wed Nov 17, 2010 5:19 pm   Post subject: loops - exit when a key is entered?

What is it you are trying to achieve?
uhm , i want to continuously run a loop until the CTRL key gets pressed. Anyone know how to do it?
I tried using getch, but the loop stops until something is inputted.
How can i do it so it can continuously run until the user pressed a key ( no enter needed)
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Nov 17, 2010 5:50 pm   Post subject: RE:loops - exit when a key is entered?

You can use Input.KeyDown to detect the up/down state of keys which do not trigger character input (which is what getch receives). Look it up in the Turing help or search these forums.
florayu




PostPosted: Wed Nov 17, 2010 5:54 pm   Post subject: Re: loops - exit when a key is entered?

but when i put getch into the loop ,
it just stops until something is inputted.
I can't get it to skip.
TokenHerbz




PostPosted: Wed Nov 17, 2010 7:11 pm   Post subject: RE:loops - exit when a key is entered?

don't use getch. use Input.KeyDown. type that down in turing and press F9 for more info on how it works.
Turing Man




PostPosted: Wed Nov 17, 2010 7:20 pm   Post subject: Re: loops - exit when a key is entered?

Turing:

var keys : array char of boolean


loop
       Input.KeyDown (keys)


% Your stuff here %

       if keys ('S') then % S can be replaced by your key of choice.
            exit
       end if

end loop


This should work.
Thanks.
SNIPERDUDE




PostPosted: Thu Nov 18, 2010 12:03 am   Post subject: RE:loops - exit when a key is entered?

A nice clean way to do that if statement would be
Turing:
exit when keys (KEY_CTRL) %CTRL key can be replaced with a key of your choice
bigman9




PostPosted: Thu Jan 20, 2011 9:16 pm   Post subject: RE:loops - exit when a key is entered?

can the key be replaced with a number?
Insectoid




PostPosted: Thu Jan 20, 2011 9:21 pm   Post subject: RE:loops - exit when a key is entered?

In quotations, yes.

ex.
code:

keys (KEY_UP_ARROW) % up arrow
keys ("5") %5
keys ("g") %g
keys(" ") %space
%you get the idea.
.
Sponsor
Sponsor
Sponsor
sponsor
bigman9




PostPosted: Thu Jan 20, 2011 9:23 pm   Post subject: RE:loops - exit when a key is entered?

ya get it. im trying to do that with my program. but its not working....


var pick: real:=0
var number: real
var keys : array char of boolean
put "Please enter the number that you wish to expariment with"
get pick
loop
Input.KeyDown (keys)

put "Select your choice of calculation:"
put "1) Square of the number"
put "2) Square root of the number"
put "3) Reciprocal of the number"
put "4) Cube of the number"
put "5) Cube root of the number"
put "0) Exit program"
get number

if number = 1 then
put pick*pick
end if

if number = 2 then
put sqrt(pick)
end if

if number = 3 then
put pick/(pick*pick)
end if

if number = 4 then
put pick*pick*pick
end if

if number = 5 then
put pick**(1/3)
end if

if keys ("0") then
exit
end if
end loop
Insectoid




PostPosted: Thu Jan 20, 2011 9:33 pm   Post subject: RE:loops - exit when a key is entered?

Why are you mixing get and input.keydown in a loop? Pick one or the other.

Right now, the loop flows as follows
code:

>>begin loop
>>>>scan pressed keys, store in array 'keys'
>>>>prompt for input, store input in number
>>>>a bunch of conditionals
>>>>check if "0" was pressed back when the loop started
>>end loop
ProgrammingFun




PostPosted: Thu Jan 20, 2011 9:38 pm   Post subject: Re: RE:loops - exit when a key is entered?

bigman9 @ Thu Jan 20, 2011 9:23 pm wrote:
ya get it. im trying to do that with my program. but its not working....


I hope you realize that posting in two threads will not help you in any way if you decide not to follow what you are advised to do: http://compsci.ca/v3/viewtopic.php?p=229061#229061
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  [ 11 Posts ]
Jump to:   


Style:  
Search: