GR_EVENT_KEYSTROKE

Name

GR_EVENT_KEYSTROKE -- Keyboard event structure

Synopsis

typedef struct 
{
    GR_EVENT_TYPE   type;
    GR_WINDOW_ID    wid;
    GR_WINDOW_ID    subwid;
    GR_COORD        rootx;
    GR_COORD        rooty;
    GR_COORD        x;
    GR_COORD        y;
    GR_BUTTON       buttons;
    GR_KEYMOD       modifiers;
    GR_KEY          ch;
    GR_SCANCODE     scancode;
} GR_EVENT_KEYSTROKE;
  

Description

The GR_EVENT_KEYSTROKE structure is used by nano-X to pass the application keyboard events.

The keystroke will be sent to the highest window that contains the mouse cursor and has selected to receive keystroke events, if that window is a decendant of the focus window. Otherwise the keystroke is sent to the focus window or it's highest ancestor that has selected to receive keystroke events.

Fields

TypeNameDescription
GR_EVENT_TYPEtypeThe event type will be either a GR_EVENT_TYPE_KEY_DOWN or a GR_EVENT_TYPE_KEY_UP type.
GR_WINDOW_IDwidThe ID of the window that the keystroke event is being sent to.
GR_WINDOW_IDsubwidThe ID of the window that the mouse is in. Generally this field will be the same as wid, but in some cases if the mouse event occurs in a decendant of wid, then this field indicates that child window.
GR_COORDrootxThe X coordinate of the mouse pointer relative to the root window.
GR_COORDrootyThe Y coordinate of the mouse pointer relative to the root window.
GR_COORDxThe X coordinate of the mouse pointer relative to the window wid.
GR_COORDyThe Y coordinate of the mouse pointer relative to the window wid.
GR_BUTTONbuttonsIndicates the mouse buttons that are being pressed.
GR_KEYMODmodifiersIndicates the status of the keyboard modifier keys.
GR_KEYchThe key that caused the keystroke event.
GR_SCANCODEscancodeThe OEM scancode for the key if it is available.

Example

The following example will print all keystroke codes to the console.

Example 3-1. Using GR_EVENT_KEYSTROKE

 
void process_key_event (GR_EVENT_KEYSTROKE *event)
{
    printf ("%s  MOD:0x%08X  CH:0x%04X  SCAN:0x%02X\n",
            (event->type == GR_EVENT_TYPE_KEY_DOWN) ? "DN" : "UP",
            event->modifiers, event->ch, event->scancode);
    fflush (stdout);
}

See Also

GR_EVENT, GR_EVENT_MOUSE.