Keyboard input/Obtain a Y or N response: Difference between revisions

Content added Content deleted
m (A GlovePIE section has been added.)
No edit summary
Line 933: Line 933:
end</lang>
end</lang>



=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>
Module Checkit {
Function GetYN$ (&Ret) {
const Y=0x59
const N=0x4E
Ret=False
Do {
if keypress(Y) then Ret=True : exit
if keypress(N) then exit
drop$=inkey$
} Always
K$=key$
do {} until filter$(Inkey$,k$)=""
=Ucase$(K$)
}
keyboard "abcde" ' feed keyboard (inkey$ get these characters)
Y=0
Print "Your answer (Y/N):"; GetYN$(&Y)
Print Y
}
Checkit
</lang>

We use a thread, using after, for one run, after 10ms, when Input wait for keypress. So when call to GetYN module exit has Y or N with Enter to keyboard. Now Input finish.

Threads runs in same namespace as the module they created. So module name and Y variable are visible.Module GetYN can't read parent module variables, except M which declared as GLOBAL. After 500ms N is returned.

Using Profiler and Print Timecount we get the real duration (using high resolution timer), of response.

<lang M2000 Interpreter>
Module CheckisToo {
Module GetYN (&Ret) {
const Y=0x59
const N=0x4E
Ret=False
Do {
If M>50 then Keyboard "N" : exit
if keypress(Y) then Ret=True : exit
if keypress(N) then exit
drop$=inkey$
\\ ensure thread MM run using wait
wait 1
} Always
Keyboard Ucase$(Key$)+Chr$(13)
}
keyboard "abcde"
Y=0
Global M=0
Thread {
M++
} as MM interval 10
While Inkey$<>"" {}
After 10 {
Module GetYN &Y
}
Profiler
Input "Your answer (Y/N):", A$
Print timecount
Print Y, M
Threads Erase
}
CheckisToo
</lang>