Keyboard input/Keypress check: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 16: Line 16:
If key was pressed, Available is set to True and Ch contains the value.
If key was pressed, Available is set to True and Ch contains the value.
If not, Available is set to False.
If not, Available is set to False.

=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}
Line 431: Line 432:
<lang AutoHotkey>; KeyIsDown := GetKeyState("KeyName" [, "Mode"])
<lang AutoHotkey>; KeyIsDown := GetKeyState("KeyName" [, "Mode"])
State := GetKeyState("RButton", "P") ; Right mouse button. P = Physical state.</lang>
State := GetKeyState("RButton", "P") ; Right mouse button. P = Physical state.</lang>

=={{header|AWK}}==
=={{header|AWK}}==
<lang AWK>
<lang AWK>
Line 622: Line 624:


end.</lang>
end.</lang>

=={{header|Elena}}==
=={{header|Elena}}==
{{trans|C#}}
{{trans|C#}}
Line 648: Line 651:
<lang Euphoria>integer key
<lang Euphoria>integer key
key = get_key() -- if key was not pressed get_key() returns -1</lang>
key = get_key() -- if key was not pressed get_key() returns -1</lang>



=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
Line 859: Line 861:
keypresswindow()
keypresswindow()
</lang>
</lang>



=={{header|Kotlin}}==
=={{header|Kotlin}}==
Line 946: Line 947:
If keypress(32) then k$=" "
If keypress(32) then k$=" "
</lang>
</lang>

=={{header|MiniScript}}==
{{works with|Mini Micro}}
<lang MiniScript>x = key.available</lang>

=={{header|Oforth}}==
=={{header|Oforth}}==
<lang Oforth>import: console
<lang Oforth>import: console
Line 959: Line 965:
System.Console receiveChar ->aChar // Wait until a character is pressed. All other keys are ignored
System.Console receiveChar ->aChar // Wait until a character is pressed. All other keys are ignored
System.Console receiveTimeout(0) ->key // Check if a key is pressed and return immediatly</lang>
System.Console receiveTimeout(0) ->key // Check if a key is pressed and return immediatly</lang>

=={{header|MiniScript}}==
{{works with|Mini Micro}}
<lang MiniScript>x = key.available</lang>


=={{header|Perl}}==
=={{header|Perl}}==
Line 1,031: Line 1,033:


This code prints <code>"doing something"</code> 10 times and then ends. Parallelly another process prints every key you type in.
This code prints <code>"doing something"</code> 10 times and then ends. Parallelly another process prints every key you type in.

=={{header|Perl 6}}==
{{works with|Rakudo|2018.10}}

<lang perl6>use Term::ReadKey;

react {
whenever key-pressed(:!echo) {
given .fc {
when 'q' { done }
default { .uniname.say }
}
}
}</lang>


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,057: Line 1,045:
$key = $Host.UI.RawUI.ReadKey()
$key = $Host.UI.RawUI.ReadKey()
}</lang>
}</lang>

=={{header|PureBasic}}==
Returns a character string if a key is pressed during the call of Inkey(). It doesn't interrupt (halt) the program flow.

If special keys (non-ASCII) have to be handled, RawKey() should be called after Inkey().
<lang PureBasic>k$ = Inkey()</lang>


=={{header|Python}}==
=={{header|Python}}==
Line 1,111: Line 1,105:
main()
main()
</lang>
</lang>

=={{header|PureBasic}}==
Returns a character string if a key is pressed during the call of Inkey(). It doesn't interrupt (halt) the program flow.

If special keys (non-ASCII) have to be handled, RawKey() should be called after Inkey().
<lang PureBasic>k$ = Inkey()</lang>


=={{header|Racket}}==
=={{header|Racket}}==
Line 1,139: Line 1,127:
(printf "You didn't press a key\n")))
(printf "You didn't press a key\n")))
</lang>
</lang>

=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.10}}

<lang perl6>use Term::ReadKey;

react {
whenever key-pressed(:!echo) {
given .fc {
when 'q' { done }
default { .uniname.say }
}
}
}</lang>


=={{header|REXX}}==
=={{header|REXX}}==
Line 1,190: Line 1,193:
y
y
</lang>
</lang>



=={{header|Scala}}==
=={{header|Scala}}==
Line 1,226: Line 1,228:
})
})
}</lang>
}</lang>

=={{header|Seed7}}==
=={{header|Seed7}}==
The library [http://seed7.sourceforge.net/libraries/keybd.htm keybd.s7i] defines
The library [http://seed7.sourceforge.net/libraries/keybd.htm keybd.s7i] defines