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 - delay() delay execution while waiting for a key press http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 delay()             Delay execution while waiting for a key press
------------------------------------------------------------------------------
 Declaration
   io.hdr

 Syntax
   func uint delay extern
   param value uint uSeconds

 Arguments
   uSeconds is the number of seconds to wait for a key press.

 Return
   The code of the pressed key, or zero if no key has been pressed.

 Description
   The delay() function waits uSeconds seconds for a key stroke. If no key
   is pressed within that time, delay() returns 0, else the keycode. The
   keycode is removed from the keyboard buffer.

 Example
   #define EXAMPLE_IO
   #include example.hdr

   func int ScreenSaver
   param const char cMessage
   // Clears the screen and then prints a moving message while waiting for
   // a key. Similar to the noburnkey() library function.
   vardef
      _HSCR nScreen
      uint  nRow, nCol
      uint  uKey
   enddef
   // if there is a key in buffer, just return without saving screen
   if iskey() != 0
      return( getkey() )
   endif
   // save the screen and initialize screen coordinates to 0
   nScreen := savescrn( 0, 0, __max_row, __max_col )
   store 0 to nRow, nCol
   // move the message around while waiting for a key
   repeat
      @ nRow, nCol ?? cMessage
      uKey := delay( 1 )          // delay a second
      @ nRow, nCol ?? space( len( cMessage ) )
   
      // increment row/column positions
      nRow++
      if nRow > __max_row
         nRow := 0
      endif
      if nCol + len( cMessage ) > __max_col
         nCol := 0
      endif
   until uKey != 0
   restorescrn( nScreen )
   return( uKey )
   endproc
   
   proc Test_delay
   vardef
      char cVar
      uint uKey
   enddef
   wait "Press a key to switch on screen saver" to cVar
   uKey := ScreenSaver( "You typed " + cVar )
   wait "You typed " + chr( uKey ) + ". Press a key to quit."
   endproc

   proc main
   Test_delay()
   endproc

See Also: getkey() ticks() waitkey() waitms()

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