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 - getkey() wait for keyboard input http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 getkey()            Wait for keyboard input
------------------------------------------------------------------------------
 Declaration
   io.hdr

 Syntax
   func uint getkey extern

 Arguments
   None.

 Return
   The code of the last key press.

 Description
   The getkey() routine waits until a key is pressed, then the key value is
   returned. The key is removed from the internal key buffer.

 Example
   #define EXAMPLE_IO
   #include example.hdr

   func logical YesOrNo
   // Accept "yes" or "no" answer and return result
   vardef
      uint nKey
   enddef
   repeat
      nKey := getkey()                    // get key press
      if nKey >= 'A' .and. nKey <= 'Z'
          nKey := nKey - 'A' + 'a'        // convert to lower case
      endif
   until nKey == 'y' .or. nKey == 'n'
   return( nKey == 'y' )
   endfunc
   
   proc ClearIt
   // A "clear typeahead" procedure
   do while iskey() <> 0
      getkey()
   enddo
   endpro
   
   proc ASCIIValue
   // Print ASCII value of keys until Escape is pressed.
   vardef
      uint nKey
   enddef
   ? "Press keys, finish with Escape"
   repeat
      nKey := getkey()
      ? chr( nKey), nKey
   until nKey == K_ESC
   endproc
   
   proc Test_getkey
   ClearIt()
   ASCIIValue()
   ? "Database exists. Continue with copy? (Y/N)"
   if YesOrNo()
      ? "Copying..."
   else
      ? "Copy cancelled"
   endif
   wait
   endproc

   proc main
   Test_getkey()
   endproc

See Also: accept delay() inkey() input iskey() keyboard() keyint() lastkey() waitkey()

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