Liberty BASIC Help Online

Using Inkey$
 
Liberty BASIC has a special variable named Inkey$ which can be used to fetch keys pressed.  This only works with the graphicbox and with windows opened for graphics.  Graphics controls handle an event called characterInput, which copies pressed-key codes into the Inkey$ variable.  See Graphics Commands, Inkey$ , Reading Mouse Events and Keystrokes, and Using Virtual Key Contants with Inkey$ for more details.  Here is a very short program demonstrating Inkey$:
 
    'Inkey$ example
    print "Keys pressed:"
    open "Inkey$ example" for graphics as #graph
    print #graph, "when characterInput [keyPressed]"
    print #graph, "trapclose [quit]"
 
[loopHere]
    'make sure #graph has input focus
    print #graph, "setfocus"
    'scan for events
    scan
    goto [loopHere]
 
[keyPressed]
    key$ = Inkey$
    if len(key$) < 2 then
        print "pressed: "; key$
      else
        print "Unhandled special key"
    end if
    goto [loopHere]
 
[quit]
    print "Quitting"
    close #graph
    end


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/