Wiki source for KeyPgGetkey


Show raw source

{{fbdoc item="title" value="GETKEY"}}----
Returns the ascii code of the first key in the keyboard buffer

{{fbdoc item="syntax"}}##
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Getkey** ( ) [[KeyPgAs|as]] [[KeyPgLong|long]]
##
{{fbdoc item="usage"}}##
//result// = **Getkey**
##
{{fbdoc item="ret"}}
The value of the ascii code returned.

{{fbdoc item="desc"}}
It returns the ascii code of the first key in the keyboard buffer. The key is removed from the buffer. If no key is present, ##**Getkey**## waits for it.
For extended keys (returning two characters), the extended code is returned in the first byte, and the regular code is returned in the second byte (the third and fourth bytes always being null at least in console mode).
WARNING: In graphics mode and depending on the key pressed, ## ** Getkey ** ## may not always return the exact same value as in console mode (for a non-extended key, the most significant bit of the ascii code byte may be propagated to the higher 3 bytes of the return value, such as a sign bit).
For a compatible code of the 2 screen modes, see the example below.

The key read is not echoed to the screen.

For a keyword not stopping the program if no key is at the buffer see ##[[KeyPgInkey|Inkey]]## or ##[[KeyPgMultikey|Multikey]]##.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/input/getkey.bas"}}%%(freebasic)
dim as long foo
do
foo = getkey
print "total return: " & foo

if( foo > 255 ) then
print "extended code: " & (foo and &hff)
print "regular code: " & (foo shr 8)
else
print "regular code: " & (foo and &hff)
end if
print
loop until foo = 27
%%


{{fbdoc item="lang"}}
- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless referenced with the alias ##**""__Getkey""**##.

{{fbdoc item="diff"}}
- New to ""FreeBASIC""

{{fbdoc item="see"}}
- ##[[KeyPgGetmouse|GetMouse]]##
- ##[[KeyPgInkey|Inkey]]##
- ##[[KeyPgInputnum|Input()]]##
- ##[[KeyPgMultikey|Multikey]]##

{{fbdoc item="back" value="CatPgInput|User Input"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode