Liberty BASIC Help Online

Inkey$
Keyboard input can only be trapped in graphics windows or graphicboxes.  When a key is pressed, the information is stored in the variable Inkey$
 
Description:
This special variable holds either a single typed character or multiple characters including a Windows virtual keycode.  Notice that because Inkey$ is a variable, it is case sensitive. Remember that at this time, only the graphics window and graphicbox controls can scan for keyboard input.  The virtual keycodes are standard Windows constants, and include arrow keys, function keys, the ALT, SHIFT, and CTRL keys, etc. 
 
If Inkey$ is a single character, that character will be the key pressed.  See the section below for a description of Inkey$ when len(Inkey$) is greater than 1.
 
  'INKEY.BAS  - how to use the Inkey$ variable
 
  open "Inkey$ example" for graphics as #graph
  print #graph, "when characterInput [fetch]"
 
[mainLoop]
  print #graph, "setfocus"
  input r$
 
[fetch]  'a character was typed!
 
  key$ = Inkey$
  if len(key$) = 1 then
      notice key$+" was pressed!"
  else
      keyValue = asc(right$(key$, 1))
      if keyValue = _VK_SHIFT then
          notice "Shift was pressed"
        else
          if keyValue = _VK_CONTROL then
              notice "Ctrl was pressed"
            else
              notice "Unhandled key pressed"
          end if
      end if
  end if
 
  WAIT
 
 
Inkey$ holds multiple key information:
If Inkey$ holds more than one character, the first character will indicate whether the Shift, Ctrl, or Alt keys was depressed when the key was pressed.  These keys have the following ASCII values:
 
Shift = 4
Ctrl  = 8
Alt  = 16
 
They can be used in any combination.  If Inkey$ contains more than one character, you can check to see which (if any) of the three special keys was also pressed by using the bitwise AND operator.  If shift alone was pressed, then the ASCII value of the first character will be 4.  If Shift and Alt were both pressed, then the ASCII value of the first character will be 20, and so on.  Special keys trigger a new value for Inkey$ when they are pressed and again when they are released.   Here is an example that uses bitwise AND to determine which special keys were pressed.
 
 
open "Inkey$ with Shift" for graphics_nf_nsb as #1
  #1 "setfocus; when characterInput [check]"
  #1 "down; place 10 30"
  #1 "\Make the mainwindow visible,"
  #1 "\then click this window and"
  #1 "\begin pressing key combinations."
  #1 "\Watch the printout in the mainwindow."
  #1 "flush"
  #1 "trapclose [quit]"
 
  wait
 
[check]
  shift=4
  ctrl=8
  alt=16
 
  a=asc(left$(Inkey$,1))
 
  if len(Inkey$)>1 then
    m$=""
 
    if a and shift then m$="shift "
    if a and ctrl then m$=m$+"ctrl "
    if a and alt then m$=m$+"alt "
    print "Special keys pressed:  " + m$
  else
    print "Key pressed:  " + Inkey$
  end if
 
  wait