wb_wait

int wb_wait ([int window [, int pause [, int flags]]])

This function creates a delay and verify if mouse buttons are pressed and/or the keyboard state. This function is useful for lengthy operations. In this case, wb_wait guarantees that the message control is sent back to the main loop, avoiding an unpleasant "freezing" effect. Using this function also provides an way to easily exit lengthy operations by constantly monitoring the keyboard and mouse.

Parameters

All parameters are optional. If window is null or not provided, the function will monitor the application's foreground window. An optional pause value, in milliseconds, can be passed to the function to provide accurate time delays. The default is 0 ms (no pause). The following constants are accepted in the flags argument to specify the events that will be monitored:

WBC_MOUSEDOWN
WBC_MOUSEUP
WBC_KEYDOWN
WBC_KEYUP

The default is WBC_KEYDOWN. Note that if you set flags to zero, the function will not monitor any keyboard or mouse button events.

Return values

The following table shows the possible return values for wb_wait.

Condition

Return value

Key pressed

Key code

Key released

Key code

Mouse button pressed

A double word (LONG) with the mouse button code¹ in the low-order word and WBC_MOUSEDOWN in the high-order word

Mouse button released

A double word (LONG) with the mouse button code¹ in the low-order word and WBC_MOUSEUP in the high-order word

¹ The mouse button code is: 1 for left button, 2 for middle button, 3 for right button.

If you monitor the return value, you may provide action based on the specific key or mouse button that generated the event.

Examples

Using wb_wait() to monitor input

for($i = 0; $i < $many; $i++) {
    do_lengthy_operation();
    if(wb_wait() == 27) {         // Check for ESC key
        if(wb_message_box($mainwin, "Are you sure you want to stop?", APPNAME, WBC_YESNO))
            break;
    }
}

Using wb_wait() to pause execution

// Some code
wb_wait($mainwin, 5000, WBC_KEYDOWN);    // Halt execution for 5 seconds or until a key is pressed
// Some more code


See also

System functions
Window functions