
-----------------------------------
florayu
Wed Nov 17, 2010 5:19 pm

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)

-----------------------------------
DemonWasp
Wed Nov 17, 2010 5:50 pm

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
Wed Nov 17, 2010 5:54 pm

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
Wed Nov 17, 2010 7:11 pm

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
Wed Nov 17, 2010 7:20 pm

Re: loops - exit when a key is entered?
-----------------------------------

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
Thu Nov 18, 2010 12:03 am

RE:loops - exit when a key is entered?
-----------------------------------
A nice clean way to do that if statement would be
exit when keys (KEY_CTRL) %CTRL key can be replaced with a key of your choice

-----------------------------------
bigman9
Thu Jan 20, 2011 9:16 pm

RE:loops - exit when a key is entered?
-----------------------------------
can the key be replaced with a number?

-----------------------------------
Insectoid
Thu Jan 20, 2011 9:21 pm

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.
[/code].

-----------------------------------
bigman9
Thu Jan 20, 2011 9:23 pm

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
Thu Jan 20, 2011 9:33 pm

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
[/code]

-----------------------------------
ProgrammingFun
Thu Jan 20, 2011 9:38 pm

Re: RE:loops - exit when a key is entered?
-----------------------------------
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
