Functions

Inkey

Extract a character from the keyboard buffer or a mouse event

Syntax

Signature
int Inkey( double seconds, int mask );

Arguments

seconds NIL checks without waiting. Finite values below 0.01 other than NIL wait indefinitely. A value of 0.01 or greater sets a timeout in seconds.

mask NIL uses the current event mask, which initially selects keyboard input.

Return value

The event code, or 0 if no matching event is available before the wait ends.

Description

Read a keyboard code, mouse event or other event selected by the mask. Combine the flags from `xdev-wtui-inkey.h` to choose which categories reach the input loop. Use `GtKeyChar()` to turn a character key code into UTF-8 text.

`Inkey( NIL, NIL )` makes a nonblocking check. `Inkey( 0, NIL )` waits for input under the current event mask, and a positive timeout of at least `0.01` seconds bounds the wait. Use `NextKey()` to inspect pending input and `LastKey()` to read the stored last event.

Example

inkey.c
#include "xdev-wtui.h"

int main( void )
{
   DispOut( "Press a key within five seconds.", NULL );
   int key = Inkey( 5, NIL );
   QOut( key == 0 ? "Timed out" : "Key received" );

   Inkey( 0, NIL );

   return 0;
}