SR Research Support Site
Functions
Message Pump functions

Functions

INT16 message_pump (void)
 
INT16 key_message_pump (void)
 
void pump_delay (UINT32 delay)
 

Detailed Description

Function Documentation

INT16 key_message_pump ( void  )

Similar to message_pump(), but only processes keypresses. This may help reduce latency.

INT16 message_pump ( void  )

Almost all experiments must run in a deterministic fashion, executing sequentially and in loops instead of the traditional Windows event-processing model. However, Windows messages must still be dispatched for keyboard input and other events. Calling getkey() will dispatch messages and return keys. The message_pump() function also dispatches messages, but does not read the keys. It can also handle messages for a modeless dialog box.

Returns
0 normally, 1 if ALT-F4 or CTRL-C pressed, or if terminal_break() called. Any loops should exit in this case.

Example: The following two programs works together to show the use of message_pump() function. In this case, writes a message to EDF file when the left mouse button is pressed.

1 // Program 1. The typical trial loop plus the message_pump()
2  #include <eyelink.h>
3 
4  // Trial loop: till timeout or response
5  while(1)
6  {
7  ...
8  // Other code for display update, trial terminating, etc.
9 
10  // Allows messages to operate in loops
11  message_pump(NULL);
12  }
1 // Program 2. Revised code in the full_screen_window_proc() function of the w32_demo_window.c
2 // module. In this case, a WM_LBUTTONDOWN message is recorded in the EDF file.
3 
4 #include <eyelink.h>
5 switch (message)
6 {
7 case WM_KEYDOWN:
8 case WM_CHAR:
9  // Processes key messages: these can be accessed by getkey()
10  process_key_messages(hwnd, message, wparam, lparam);
11  break;
12 
13 case WM_LBUTTONDOWN:
14  eyemsg_printf("Left button is down");
15  break;
16  ...
17  // Other windows messages and events
18 }

Output:

1 MSG 11662745 left button is down
2 MSG 11663048 left button is down
3 BUTTON 11665520 4 1
4 MSG 11665521 ENDBUTTON 4
See also
pump_delay()
void pump_delay ( UINT32  delay)

During calls to msec_delay(), Windows is not able to handle messages. One result of this is that windows may not appear. This is the preferred delay function when accurate timing is not needed. It calls message_pump() until the last 20 milliseconds of the delay, allowing Windows to function properly. In rare cases, the delay may be longer than expected. It does not process modeless dialog box messages.

Parameters
delayNumber of milliseconds to delay.

Example:

1 // This program illustrates the use of pump_delay() at the end of trial
2 #include <eyelink.h>
3 
4 // End recording: adds 100 msec of data to catch final events
5 static void end_trial(void)
6 {
7  ...
8  // Add code here to clean the display
9 
10  // Ensure we release realtime lock
11  end_realtime_mode();
12  // Delay for 100 msec, allow Windows to clean up
13  pump_delay(100);
14 
15  // halt recording, return when tracker finished mode switch
16  stop_recording();
17 }
See also
msec_delay() and message_pump()

Copyright ©2002-2023, SR Research Ltd.