Definition: | integer i = wait_key() |
Description: | Return the next key pressed by the user. Do not return until a key is pressed. |
Comments: | You could achieve the same result using
get_key() as follows:
while 1 do k = get_key() if k!=-1 then exit end if end while However, this "busy waiting" would tend to slow the system down, whereas wait_key() lets the operating system do other useful work while your program is waiting for the user to press a key. You could also use getc(0), assuming file number 0 was input from the keyboard, except that you would not pick up the special codes for function keys, arrow keys etc. Note that wait_key() is usually for console applications only and has no place in a gui application. It can only catch keystrokes when the console (assuming you have one) has focus; when the gui has focus then the gui absorbs any keystrokes, as you should expect. One obvious exception is that sometimes you might use wait_key() at the very end of a run, after the gui has closed, to prevent the console and any messages on it from immediately dissappearing. |
Example Program: | demo\rosetta\Cursor_movement.exw |
See Also: | get_key, getc |