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 - definesetkey() assign a function to a key press http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 definesetkey()      Assign a function to a key press
------------------------------------------------------------------------------
 Declaration
   io.hdr

 Syntax
   func ulong definesetkey extern
   param value uint  uKeyCode, ;
         value ulong pFunction

 Arguments
   uKeyCode is the key receiving the assignment.
   pFunction is the function to associate with the key.

 Return
   An ulong integer whose value depends on the action taken, as listed
   in the table below.

   ---------------------------------------------------------------------
   Value               Description
   ---------------------------------------------------------------------
   0                   Successful installation of a new key/function
                       combination.

   Any other value     A new function has been assigned to an already
                       defined key; the return value contains the
                       address of the previously assigned function.
                       This may be saved in a variable for restoration
                       later.

   0xffffffff          The function could not be assigned to the key
                       because the internal table is full.
   ---------------------------------------------------------------------

 Description
   The definesetkey() function assigns a function to the specified key.
   The functions will be automatically called when the associated key is
   pressed.

 Example
   #define EXAMPLE_IO
   #include example.hdr

   vardef static
      ulong   pFunc    := 0
      logical lFurther := .f.
   enddef
   
   proc Proceed static
   ? "Proceed..."
   lFurther := .t.
   endproc
   
   proc SayHello static
   ? "hello"
   endproc
   
   proc SayWorld static
   ? "world"
   endproc
   
   proc Test_definesetkey
   ? "Press F1 to test, Esc to finish"
   initsetkey()                             // initialize set key system
   definesetkey( K_F1,  &SayHello )         // install SayHello()
   definesetkey( K_ESC, &Proceed )          // install Proceed()
   dispatchkey()                            // start key processing
   do while .not. lFurther                  // get key presses
      inkey()
   enddo
   pFunc := definesetkey( K_F1, &SayWorld ) // install SayWorld()
   lFurther := .f.
   do while .not. lFurther                  // get key presses
      inkey()
   enddo
   definesetkey( K_F1, pFunc )              // restore previous handler
   lFurther := .f.
   do while .not. lFurther                  // get key presses
      inkey()
   enddo
   endproc

   proc main
   Test_definesetkey()
   endproc

See Also: dispatchkey() getsetkey() initsetkey()

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