ConInKey$ function



StringVar$ = ConInKey$


Legacy Syntax:

StringVar$ = INKEY$


Pseudo-object Syntax:

StringVar$ = CON.INKEY$


Returns a keyboard or mouse event from the console input buffer, if available.


Nothing is echoed to the screen. Returns immediately, regardless of whether or not there are input events to return.


A string of 0, 1, or 2 characters is returned that reflects the status of the keyboard buffer. A string of 4 characters may also be returned if mouse event trapping is enabled. ConInKey$ will always read keys from the keyboard, regardless of redirection status.


A null string (LEN(StringVar$) = 0) means that the buffer is empty (no key or mouse event is available).


A string length of one (LEN(StringVar$) = 1) means that a printable character key or control code key was pressed. Values between 1 and 31 indicate a control code.


A string length of two (LEN(StringVar$) = 2) means that a special key was pressed. In this case, the first character in the string has a value of zero, and the second is the extended keyboard code. See the table below for values.


A string length of four (LEN(StringVar$) = 4) means that a mouse event was retrieved. In this case, the first two characters in the string have a value of 255. The third character is an event code, while the fourth character defines the button that was pressed or released.


Event code:

         1 = movement            4 = button press

         2 = double-click        8 = button release


Button code:

         0 = no button           4 = second left button

         1 = left button         8 = third left button

         2 = right button       16 = fourth left button


For example, moving the mouse with the left button pressed will return CHR$(255, 255, 1, 1). Button presses can be combined. For example, pressing the left and right mouse buttons together will return CHR$(255, 255, 4, 3). The mouse must be enabled with the ConMouse and ConMouseOn commands for mouse events to be reported. Use the ConMouseRow and ConMouseCol functions after calling ConInKey$ to determine the mouse position at the time of the event.


Presses of Shift, Ctrl, Alt and the lock keys are not reported by ConInKey$. Use the ConInShift function after calling ConInKey$ (with or without a non-null result) to determine the state of these keys. If you need to detect changes in the shift/lock states, keep a local copy of the ConInShift value.


Two-character key codes:

         0,59 = F1

         0,60 = F2

         0,61 = F3

         0,62 = F4

         0,63 = F5

         0,64 = F6

         0,65 = F7

         0,66 = F8

         0,67 = F9

         0,68 = F10

         0,71 = Home

         0,79 = End

         0,73 = PgUp

         0,81 = PgDn

         0,72 = CursorUp

         0,75 = CursorLeft

         0,77 = CursorRight

         0,80 = CursorDown

         0,82 = Ins

         0,83 = Del

         0,87 = F11

         0,88 = F12




#IF %DEF(%PB_CC32)

  StringVar$ = INKEY$


  StringVar$ = ConInKey$



CON.INKEY$ or CONSOLE.INKEY$ may be substituted for INKEY$ in programs written for PB/CC6.


See also: ConInShift, ConInStat, ConWaitKey$, ConMouse, ConMouseOn, ConMouseRow, ConMouseCol