Computer Science Canada loops - exit when a key is entered? |
Author: | florayu [ 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) |
Author: | DemonWasp [ 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. |
Author: | florayu [ 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. |
Author: | TokenHerbz [ 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. |
Author: | Turing Man [ Wed Nov 17, 2010 7:20 pm ] | ||
Post subject: | Re: loops - exit when a key is entered? | ||
This should work. Thanks. |
Author: | SNIPERDUDE [ 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
|
Author: | bigman9 [ 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? |
Author: | Insectoid [ Thu Jan 20, 2011 9:21 pm ] | ||
Post subject: | RE:loops - exit when a key is entered? | ||
In quotations, yes. ex.
|
Author: | bigman9 [ 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 |
Author: | Insectoid [ 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
|
Author: | ProgrammingFun [ 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 |