Revision history for KeyPgInkey


Revision [24378]

Last edited on 2020-09-12 02:30:31 by fxm ['$' suffix behavior change]
Additions:
- The string type suffix "$" is required in the //[[CompilerOptlang|-lang qb]]// dialect.
- The string type suffix "$" is ignored in the //[[CompilerOptlang|-lang fb]]// dialect, warn only with the //[[CompilerOptw|-w suffix]]// compile option (or //[[CompilerOptw|-w pedantic]]// compile option).
Deletions:
- The string type suffix "$" is obligatory in the //[[CompilerOptlang|-lang qb]]// dialect.
- The string type suffix "$" is forbidden in the //[[CompilerOptlang|-lang fb]]// dialect.


Revision [22475]

Edited on 2018-09-03 16:39:46 by JeffMarshall [small fix to compile example]
Additions:
'' Compile with -lang fblite or qb
#lang "fblite"


Revision [21917]

Edited on 2017-09-20 14:25:31 by fxm [String type suffix "$" forbidden in fb dialect]
Additions:
- The string type suffix "$" is obligatory in the //[[CompilerOptlang|-lang qb]]// dialect.
- The string type suffix "$" is optional in the //[[CompilerOptlang|-lang fblite]]// dialect.
- The string type suffix "$" is forbidden in the //[[CompilerOptlang|-lang fb]]// dialect.
Deletions:
- The string type suffix ##$## is optional in the //[[CompilerOptlang|-lang fblite]]// and //[[CompilerOptlang|-lang fb]]// dialects, but required in the //[[CompilerOptlang|-lang qb]]// dialect.


Revision [20946]

Edited on 2016-03-13 03:42:46 by fxm [Formatting]

No Differences

Revision [20273]

Edited on 2016-02-10 16:01:26 by DkLwikki [Update link format]
Additions:
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Inkey** ( ) [[KeyPgAs|as]] [[KeyPgString|string]]
Peeks into the keyboard buffer and returns a ##[[KeyPgString|String]]## representation of the first character, if any, found. The key is then removed from the buffer, and is not echoed to the screen. If the keyboard buffer is empty, an empty string (##"####"##) is immediately returned without waiting for keys.
If the key is in the ASCII character set, a one-character ##[[KeyPgString|String]]## consisting of that character is returned. If the key is an "extended" one (numeric pad, cursors, functions) a two-character ##[[KeyPgString|String]]## is returned, the first of which is the extended character (//See dialect differences below//)
See also ##[[KeyPgInputnum|Input()]]## or ##[[KeyPgGetkey|Getkey]]##, or ##[[KeyPgSleep|Sleep]]## to wait for a key press if the keyboard buffer is empty.
Case "A" To "Z", "a" To "z": Print "Letter: " & k
Case "1" To "9": Print "Number: " & k
Case Chr$(32): Print "Space"
Case Chr$(27): Print "Escape"
Case Chr$(9): Print "Tab"
Case Chr$(8): Print "Backspace"
Case Chr$(32) To Chr$(127)
Print "Printable character: " & k
Case EXTCHAR & "G": Print "Up Left / Home"
Case EXTCHAR & "H": Print "Up"
Case EXTCHAR & "I": Print "Up Right / PgUp"
Case EXTCHAR & "K": Print "Left"
Case EXTCHAR & "L": Print "Center"
Case EXTCHAR & "M": Print "Right"
Case EXTCHAR & "O": Print "Down Left / End"
Case EXTCHAR & "P": Print "Down"
Case EXTCHAR & "Q": Print "Down Right / PgDn"
Case EXTCHAR & "R": Print "Insert"
Case EXTCHAR & "S": Print "Delete"
Case EXTCHAR & "k": Print "Close window / Alt-F4"
Case EXTCHAR & Chr$(59) To EXTCHAR & Chr$(68)
Print "Function key: F" & Asc(k, 2) - 58
Case EXTCHAR & Chr$(133) To EXTCHAR & Chr$(134)
Print "Function key: F" & Asc(k, 2) - 122
Case Else
If Len(k) = 2 Then
Print Using "Extended character: chr$(###, ###)"; Asc(k, 1); Asc(k, 2)
ElseIf Len(k) = 1 Then
Print Using "Character chr$(###)"; Asc(k)
End If
- The extended character is ##[[KeyPgChr|Chr]](255)## in the //[[CompilerOptlang|-lang fb]]// and //[[CompilerOptlang|-lang fblite]]// dialects.
- In the //[[CompilerOptlang|-lang qb]]// dialect, the extended character depends on how the keyword is written. If the QB form ##**Inkey$**## is used, the extended character is ##[[KeyPgChr|Chr]](0)##. If it is referenced as ##**""__Inkey""**##, the extended char is ##[[KeyPgChr|Chr]](255)##.
- In all other dialects, the extended char is always ##[[KeyPgChr|Chr]](255)##.
- The string type suffix ##$## is optional in the //[[CompilerOptlang|-lang fblite]]// and //[[CompilerOptlang|-lang fb]]// dialects, but required in the //[[CompilerOptlang|-lang qb]]// dialect.
- None in the //[[CompilerOptlang|-lang qb]]// dialect.
- QBasic returned a ##[[KeyPgChr|Chr]](0)## as the first character for an extended key, but ""FreeBASIC"" returns ##[[KeyPgChr|Chr]](255)## as the first character in the //[[CompilerOptlang|-lang fb]]// and //[[CompilerOptlang|-lang fblite]]// dialects.
- ##[[KeyPgSleep|Sleep]]##
- ##[[KeyPgGetkey|Getkey]]##
- ##[[KeyPgInputnum|Input()]]##
- ##[[KeyPgMultikey|Multikey]]##
Deletions:
[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Inkey** ( ) [[KeyPgAs as]] [[KeyPgString string]]
Peeks into the keyboard buffer and returns a ##[[KeyPgString String]]## representation of the first character, if any, found. The key is then removed from the buffer, and is not echoed to the screen. If the keyboard buffer is empty, an empty string (##"####"##) is immediately returned without waiting for keys.
If the key is in the ASCII character set, a one-character ##[[KeyPgString String]]## consisting of that character is returned. If the key is an "extended" one (numeric pad, cursors, functions) a two-character ##[[KeyPgString String]]## is returned, the first of which is the extended character (//See dialect differences below//)
See also ##[[KeyPgInputnum Input()]]## or ##[[KeyPgGetkey Getkey]]##, or ##[[KeyPgSleep Sleep]]## to wait for a key press if the keyboard buffer is empty.
Case "A" To "Z", "a" To "z": Print "Letter: " & k
Case "1" To "9": Print "Number: " & k
Case Chr$(32): Print "Space"
Case Chr$(27): Print "Escape"
Case Chr$(9): Print "Tab"
Case Chr$(8): Print "Backspace"
Case Chr$(32) To Chr$(127)
Print "Printable character: " & k
Case EXTCHAR & "G": Print "Up Left / Home"
Case EXTCHAR & "H": Print "Up"
Case EXTCHAR & "I": Print "Up Right / PgUp"
Case EXTCHAR & "K": Print "Left"
Case EXTCHAR & "L": Print "Center"
Case EXTCHAR & "M": Print "Right"
Case EXTCHAR & "O": Print "Down Left / End"
Case EXTCHAR & "P": Print "Down"
Case EXTCHAR & "Q": Print "Down Right / PgDn"
Case EXTCHAR & "R": Print "Insert"
Case EXTCHAR & "S": Print "Delete"
Case EXTCHAR & "k": Print "Close window / Alt-F4"
Case EXTCHAR & Chr$(59) To EXTCHAR & Chr$(68)
Print "Function key: F" & Asc(k, 2) - 58
Case EXTCHAR & Chr$(133) To EXTCHAR & Chr$(134)
Print "Function key: F" & Asc(k, 2) - 122
Case Else
If Len(k) = 2 Then
Print Using "Extended character: chr$(###, ###)"; Asc(k, 1); Asc(k, 2)
ElseIf Len(k) = 1 Then
Print Using "Character chr$(###)"; Asc(k)
End If
- The extended character is ##[[KeyPgChr Chr]](255)## in the //[[CompilerOptlang -lang fb]]// and //[[CompilerOptlang -lang fblite]]// dialects.
- In the //[[CompilerOptlang -lang qb]]// dialect, the extended character depends on how the keyword is written. If the QB form ##**Inkey$**## is used, the extended character is ##[[KeyPgChr Chr]](0)##. If it is referenced as ##**""__Inkey""**##, the extended char is ##[[KeyPgChr Chr]](255)##.
- In all other dialects, the extended char is always ##[[KeyPgChr Chr]](255)##.
- The string type suffix ##$## is optional in the //[[CompilerOptlang -lang fblite]]// and //[[CompilerOptlang -lang fb]]// dialects, but required in the //[[CompilerOptlang -lang qb]]// dialect.
- None in the //[[CompilerOptlang -lang qb]]// dialect.
- QBasic returned a ##[[KeyPgChr Chr]](0)## as the first character for an extended key, but ""FreeBASIC"" returns ##[[KeyPgChr Chr]](255)## as the first character in the //[[CompilerOptlang -lang fb]]// and //[[CompilerOptlang -lang fblite]]// dialects.
- ##[[KeyPgSleep Sleep]]##
- ##[[KeyPgGetkey Getkey]]##
- ##[[KeyPgInputnum Input()]]##
- ##[[KeyPgMultikey Multikey]]##


Revision [15304]

Edited on 2011-10-01 07:13:21 by CountingPine [Remove CamelCase link]
Additions:
- QBasic returned a ##[[KeyPgChr Chr]](0)## as the first character for an extended key, but ""FreeBASIC"" returns ##[[KeyPgChr Chr]](255)## as the first character in the //[[CompilerOptlang -lang fb]]// and //[[CompilerOptlang -lang fblite]]// dialects.
Deletions:
- QBasic returned a ##[[KeyPgChr Chr]](0)## as the first character for an extended key, but FreeBASIC returns ##[[KeyPgChr Chr]](255)## as the first character in the //[[CompilerOptlang -lang fb]]// and //[[CompilerOptlang -lang fblite]]// dialects.


Revision [15300]

Edited on 2011-10-01 07:12:39 by CountingPine [Few more keys detected in example: Ins, Del, Close Window/Alt-F4]
Additions:
Case Chr$(9): Print "Tab"
Case Chr$(8): Print "Backspace"
Case EXTCHAR & "R": Print "Insert"
Case EXTCHAR & "S": Print "Delete"
Case EXTCHAR & "k": Print "Close window / Alt-F4"


Revision [14580]

Edited on 2010-02-18 07:34:50 by TheAdventMaster [Few more keys detected in example: Ins, Del, Close Window/Alt-F4]
Additions:
See also ##[[KeyPgInputnum Input()]]## or ##[[KeyPgGetkey Getkey]]##, or ##[[KeyPgSleep Sleep]]## to wait for a key press if the keyboard buffer is empty.
Deletions:
See also ##[[KeyPgInputnum Input()]]## or ##[[KeyPgGetkey Getkey]]##. ##[[KeyPgSleep Sleep]]## will wait for a key press if the keyboard buffer is empty.


Revision [14579]

Edited on 2010-02-18 07:34:22 by TheAdventMaster [Few more keys detected in example: Ins, Del, Close Window/Alt-F4]
Additions:
See also ##[[KeyPgInputnum Input()]]## or ##[[KeyPgGetkey Getkey]]##. ##[[KeyPgSleep Sleep]]## will wait for a key press if the keyboard buffer is empty.
Deletions:
See also ##[[KeyPgInputnum Input()]]## or ##[[KeyPgGetkey Getkey]]##. ##[[KeyPgSleep Sleep]]## can wait for a key press if the keyboard buffer is empty.


Revision [14578]

Edited on 2010-02-18 07:32:16 by TheAdventMaster [Removed information on using sleep when inkey is used for input.]
Additions:
See also ##[[KeyPgInputnum Input()]]## or ##[[KeyPgGetkey Getkey]]##. ##[[KeyPgSleep Sleep]]## can wait for a key press if the keyboard buffer is empty.
Deletions:
To wait for a key press, ##**Inkey**## can be polled in a loop. However, a simple loop will hog the CPU, so it is worth putting a short ##[[KeyPgSleep Sleep]]## inside the loop, to free up the CPU. The result is that the ##**Inkey**## check will run every few milliseconds, instead of happening as fast as possible.
See also ##[[KeyPgInputnum Input()]]## or ##[[KeyPgGetkey Getkey]]##. In many cases, ##[[KeyPgSleep Sleep]]## can also be used on its own to wait for a key press.


Revision [13658]

Edited on 2008-08-25 13:05:18 by CountingPine [Add extended example; mention Sleep; misc]
Additions:
The first character found in the keyboard buffer, or an empty string (##"####"##) if none found.
Peeks into the keyboard buffer and returns a ##[[KeyPgString String]]## representation of the first character, if any, found. The key is then removed from the buffer, and is not echoed to the screen. If the keyboard buffer is empty, an empty string (##"####"##) is immediately returned without waiting for keys.
To wait for a key press, ##**Inkey**## can be polled in a loop. However, a simple loop will hog the CPU, so it is worth putting a short ##[[KeyPgSleep Sleep]]## inside the loop, to free up the CPU. The result is that the ##**Inkey**## check will run every few milliseconds, instead of happening as fast as possible.
See also ##[[KeyPgInputnum Input()]]## or ##[[KeyPgGetkey Getkey]]##. In many cases, ##[[KeyPgSleep Sleep]]## can also be used on its own to wait for a key press.
sleep 1, 1
{{fbdoc item="filename" value="examples/manual/input/inkeyext.bas"}}%%(freebasic)
#if __FB_LANG__ = "qb"
#define EXTCHAR Chr$(0)
#else
#define EXTCHAR Chr(255)
#endif
Dim k As String
Print "Press a key, or Escape to end"
Do
k = Inkey$
Select Case k
Case "A" To "Z", "a" To "z": Print "Letter: " & k
Case "1" To "9": Print "Number: " & k
Case Chr$(32): Print "Space"
Case Chr$(27): Print "Escape"
Case Chr$(32) To Chr$(127)
Print "Printable character: " & k
Case EXTCHAR & "G": Print "Up Left / Home"
Case EXTCHAR & "H": Print "Up"
Case EXTCHAR & "I": Print "Up Right / PgUp"
Case EXTCHAR & "K": Print "Left"
Case EXTCHAR & "L": Print "Center"
Case EXTCHAR & "M": Print "Right"
Case EXTCHAR & "O": Print "Down Left / End"
Case EXTCHAR & "P": Print "Down"
Case EXTCHAR & "Q": Print "Down Right / PgDn"
Case EXTCHAR & Chr$(59) To EXTCHAR & Chr$(68)
Print "Function key: F" & Asc(k, 2) - 58
Case EXTCHAR & Chr$(133) To EXTCHAR & Chr$(134)
Print "Function key: F" & Asc(k, 2) - 122
Case Else
If Len(k) = 2 Then
Print Using "Extended character: chr$(###, ###)"; Asc(k, 1); Asc(k, 2)
ElseIf Len(k) = 1 Then
Print Using "Character chr$(###)"; Asc(k)
End If
End Select
If k = Chr$(27) Then Exit Do
Sleep 1, 1
Loop
- The extended character is ##[[KeyPgChr Chr]](255)## in the //[[CompilerOptlang -lang fb]]// and //[[CompilerOptlang -lang fblite]]// dialects.
- In the //[[CompilerOptlang -lang qb]]// dialect, the extended character depends on how the keyword is written. If the QB form ##**Inkey$**## is used, the extended character is ##[[KeyPgChr Chr]](0)##. If it is referenced as ##**""__Inkey""**##, the extended char is ##[[KeyPgChr Chr]](255)##.
- In all other dialects, the extended char is always ##[[KeyPgChr Chr]](255)##.
- The string type suffix ##$## is optional in the //[[CompilerOptlang -lang fblite]]// and //[[CompilerOptlang -lang fb]]// dialects, but required in the //[[CompilerOptlang -lang qb]]// dialect.
- QBasic returned a ##[[KeyPgChr Chr]](0)## as the first character for an extended key, but FreeBASIC returns ##[[KeyPgChr Chr]](255)## as the first character in the //[[CompilerOptlang -lang fb]]// and //[[CompilerOptlang -lang fblite]]// dialects.
- ##[[KeyPgSleep Sleep]]##
Deletions:
The first character found in the keyboard buffer, or the null string (##"####"##) if none found.
Peeks into the keyboard buffer and returns a ##[[KeyPgString String]]## representation of the first character, if any, found. The key is then removed from the buffer, and is not echoed to the screen. If the keyboard buffer is empty, the NULL string (##"####"##) is immediately returned without waiting for keys.
To wait for a key press, ##**Inkey**## can be polled in a loop. See also ##[[KeyPgInputnum Input]]## or ##[[KeyPgGetkey Getkey]]##.
- The extended character is ##Chr(255)## in the //[[CompilerOptlang -lang fb]]// and //[[CompilerOptlang -lang fblite]]// dialects.
- In the //[[CompilerOptlang -lang qb]]// dialect, the extended character depends on how the keyword is written. If the QB form ##**Inkey$**## is used the extended character is ##Chr(0)##, while if written as ##**""__Inkey""**## the extended char is ##Chr(255)## as in the other dialects.
- The string type suffix "$" is optional in the //[[CompilerOptlang -lang fblite]]// and //[[CompilerOptlang -lang fb]]// dialects.
- QBasic returned a ##Chr(0)## as the first character for an extended key, but FreeBASIC returns ##Chr(255)## as the first character in the //[[CompilerOptlang -lang fb]]// and //[[CompilerOptlang -lang fblite]]// dialects


Revision [12942]

The oldest known version of this page was created on 2008-04-18 15:12:36 by AntoniGual [Add extended example; mention Sleep; misc]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode