Keyboard input/Flush the keyboard buffer: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 243:
println("Goodbye!")
}</lang>
 
=={{header|M2000 Interpreter}}==
M2000 run in M2000 Environment so has total control, including keyboard. Here we read keyboard from console (we can't read with this way for froms, we have to read from events).
 
Inkey$ return "" if not key pressed, or the key. Return unicode char
 
Key$ wait for key, to press, we can use Keyboard to send keys
 
inkey(1000) wait for a new key to press, we can't use Keyboard to send keys, there is no auto repeat, so if we have a second read inkey(1000) and we keep press the same key, nothing happen (return -1, as no new key)
 
Keypress(32) we can read if a space key is now pressed. Can't read keyboard if m2000 environment application hasn't focus. It's not a key logger. Keypress(1) read left mouse button, Keypress(2) read right mouse button.
 
 
<lang M2000 Interpreter>
Module Checkit {
\\ feed keyboard
Keyboard "abcd"
\\ Work in Windows not in Linux (no Osk.exe exist)
\\ no error return in linux
Keyboard ! 'open virtual keyboard
Wait 3000
\\ flush keyboard
\\ we can use Do or Repeat (is the same)
Repeat {
a$=inkey$
if a$="" then Print :exit
Print a$;
} Always
}
Checkit
</lang>
 
This isn't the task. Input ends when statement Input End occur, in a thread.
 
Statement After make a thread for one time only. When in Input interpreter wait for A$ to input, threads allowed to run. If we write but forget to press enter then input flush. If no input statement run then nothing happen when Input End run.
 
 
<lang M2000 Interpreter>
Module checkit {
Print "You have 3 seconds to write your name (press enter)"
After 3000 {
Input End
}
Input "Your name:", A$
If A$="" Then Print "Not Ready" : Exit
Print "Ok:";A$
}
Checkit
</lang>
 
 
=={{header|Nim}}==
Anonymous user