Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - on key do redirect keyboard input through a function http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 on key do           Redirect keyboard input through a function
------------------------------------------------------------------------------
 Syntax
   on key do [xProc]

 Arguments
   xProc is a keyboard handler function.

 Description
   The on key do command redirects all keyboard input to go through the
   specified function. This allows you to control and filter all keyboard
   I/O.

   The function xProc is invoked every time the keyboard is pressed.
   xProc is responsible for filtering important keystrokes. xProc must be
   a uint or int function. Any key that is not filtered by xProc must be
   returned to the caller. xProc is always called, regardless of the
   current keyboard driver installed via keydos() or keybios().

   If xProc is not specified, then keyboard I/O is redirected through
   the runtime library system.

 Example
   #define EXAMPLE_SYSTEM
   #include example.hdr

   // Use on key do to install a generic help system
   
   vardef static
      logical lEntered := .f.
   enddef
   
   func int HelpDisp static
   vardef
      uint uKey
   enddef
   uKey := lastkey()
   if uKey == K_F1 .and. .not. lEntered
      lEntered := .t.      // don't process F1 within the help routine
      alert( "This is the help text", " OK ", BLUE_WHITE, BLACK_WHITE )
      uKey := 0
      lEntered := .f.
   endif
   return( uKey )
   endproc
   
   proc Test_onkeydo
   on key do HelpDisp
   ? "Press F1 for help, Esc for exit"
   do while inkey() != K_ESC
   enddo
   endproc

   proc main
   Test_onkeydo()
   endproc

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson