Input.KeyDown (chars) not working
Author |
Message |
Aerii
|
Posted: Fri Apr 10, 2015 3:59 pm Post subject: Input.KeyDown (chars) not working |
|
|
What is it you are trying to achieve?
I'm trying to make it so when Enter is pressed it will start the code inside (Which is pretty much the program)
What is the problem you are having?
When I do:
Code: | colour (9)
put "Press Enter to being your conversation with Turing!"
loop
Input.KeyDown (chars)
if chars (KEY_ENTER) then
(MY CODE HERE)
else
cls
put "Exiting program in 5 seconds."
delay (1000)
cls
put "Exiting program in 4 seconds.."
delay (1000)
cls
put "Exiting program in 3 seconds..."
delay (1000)
cls
put "Exiting program in 2 seconds.."
delay (1000)
cls
colour (4)
put "Exiting program in 1 second."
delay (1000)
cls
Draw.FillBox (0, 0, maxx, maxy, black)
quit
end if
end loop
|
It just goes straight to the else section of the code and skips everything else. So if I press enter or not then nothing happens.
Describe what you have tried to solve this problem
I've tried looking it up on here and using getch but none of that works.
EDIT: FOUND THIS OUT!
code: | elsif chars(KEY_UP_ARROW) then
cls
put "Exiting program in 5 seconds."
delay (1000)
cls
put "Exiting program in 4 seconds.."
delay (1000)
cls
put "Exiting program in 3 seconds..."
delay (1000)
cls
put "Exiting program in 2 seconds.."
delay (1000)
cls
colour (4)
put "Exiting program in 1 second."
delay (1000)
cls
Draw.FillBox (0, 0, maxx, maxy, black)
end if
end loop
quit | I put code: | elseif chars (KEY_UP_ARROW) then | just to test and now the whole program works but it only does the else if the up arrow key is pressed obviously. Not sure how to make it for all keys.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: | % *Variables*
var space : string
space := ""
var name : string
var answer : string
var chars : array char of boolean
|
Please specify what version of Turing you are using
Version 4.11 or something
EDIT: I've figured out I will just use KEY_ESC for exiting the program. It works well and I don't need it to be any key but enter. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Sat Apr 11, 2015 8:07 am Post subject: RE:Input.KeyDown (chars) not working |
|
|
Input.KeyDown is almost certainly working correctly. Your loop, however, doesn't: it will only ever call Input.KeyDown one time. If you aren't holding down the Enter key at that time, then it will go into the 'else' clause and stay there for the next several seconds before quitting.
If you wanted to make an "interactive" timer that waits 5 seconds for you to press Enter, then you need to look for the "game loop" posts on this site. Those will tell you how to poll for user input while also updating things on the screen (like "Exiting program in N seconds...") |
|
|
|
|
|
|
|