keyhook.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 17 Oct 2015 20:24:39 -0400
branchgtkui
changeset 45 cf6a06f368e6
parent 17 e884dbb403cc
child 48 5b2b972c5078
permissions -rw-r--r--
Moved to a more robust GTK UI. This removes the popup windows, in favor of something searchable, etc, but it's not without its problems, too, so it's sitting in branch until I decide I really like it or I should replace it with SDL or something. :) (If someone can figure out how to get the window to steal focus when popped up, that would fix the most egregious issue, but there are other small details that need fixing, too.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
// !!! FIXME: this is X11 specific.  :(
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
#include <stdio.h>
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
     4
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
     5
#if 1
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
#include <stdlib.h>
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
#include <string.h>
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
#include <pthread.h>
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#include <unistd.h>
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include <X11/Xlib.h>
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include <X11/Xlibint.h>
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include <X11/extensions/record.h>
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include "keyhook.h"
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
static volatile int keyPressFlags = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
static volatile int sawKeyCombo = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
static void keyhookCallback(XPointer priv, XRecordInterceptData *data)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
{
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
    const xEvent *xev = (const xEvent *) data->data;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
    if (data->category == XRecordFromServer)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
    {
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
        const BYTE keycode = xev->u.u.detail;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
        if (xev->u.u.type == KeyPress)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
        {
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
            // !!! FIXME: don't hardcode these keycodes.
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
            if ((keycode == 64) && (keyPressFlags == 0))
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
                keyPressFlags++;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
            else if ((keycode == 133) && (keyPressFlags == 1))
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
                keyPressFlags++;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
            else if ((keycode == 51) && (keyPressFlags == 2))
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
            {
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
                sawKeyCombo = 1;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
                keyPressFlags = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
            } // else if
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
            else
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
                keyPressFlags = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
        } // if
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
        else if (xev->u.u.type == KeyRelease)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
        {
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
            keyPressFlags = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
        } // else if
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    } // if
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
    XRecordFreeData(data);
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
} // keyhookCallback
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
// every example I've seen needs two Display connections...one for the
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
//  keyhook, and one to control it.
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
static Display *ctrldpy = NULL;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
static Display *datadpy = NULL;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
static XRecordContext xrc = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
int initKeyHook(void)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
{
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    int major = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    int minor = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
    XRecordRange *xrr = NULL;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    XRecordClientSpec xrcs = XRecordAllClients;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    if (ctrldpy)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
        return 0;  // already initialized.
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
    ctrldpy = XOpenDisplay(NULL);
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
    if (!ctrldpy)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
        goto failed;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
    XSynchronize(ctrldpy, True);
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
    datadpy = XOpenDisplay(NULL);
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
    if (!datadpy)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
        goto failed;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
    else if (!XRecordQueryVersion(ctrldpy, &major, &minor))
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
        goto failed;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
    else if ((xrr = XRecordAllocRange()) == NULL)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
        goto failed;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
    memset(xrr, '\0', sizeof (*xrr));
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
    xrr->device_events.first = KeyPress;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
    xrr->device_events.last = KeyPress;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
    if ((xrc = XRecordCreateContext(ctrldpy, 0, &xrcs, 1, &xrr, 1)) == 0)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
        goto failed;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
    else if (!XRecordEnableContextAsync(datadpy, xrc, keyhookCallback, NULL))
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
        goto failed;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
    XFree(xrr);
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
    xrr = NULL;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    return 1;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
failed:
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
    deinitKeyHook();
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
    if (xrr) XFree(xrr);
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    return 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
} // initKeyHook
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
void deinitKeyHook(void)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
{
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
    if (ctrldpy)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
    {
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
        if (xrc)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
        {
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
            XRecordDisableContext(ctrldpy, xrc);
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
            XRecordFreeContext(ctrldpy, xrc);
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
        } // if
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
        XCloseDisplay(ctrldpy);
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
    } // if
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
    if (datadpy)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
        XCloseDisplay(datadpy);
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
    ctrldpy = NULL;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
    datadpy = NULL;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
    xrc = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
    sawKeyCombo = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
    keyPressFlags = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
} // deinitKeyHook
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
int pumpKeyHook(void)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
{
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
    if (!datadpy)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
        return 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
    sawKeyCombo = 0;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    XRecordProcessReplies(datadpy);
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    return sawKeyCombo;
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
} // pumpKeyHook
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   135
#else
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   136
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   137
int initKeyHook(void) { return 1; }
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   138
void deinitKeyHook(void) {}
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   139
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   140
int pumpKeyHook(void)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   141
{
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   142
static int x = 50;
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   143
const int retval = (x == 50);
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   144
if (++x > 50) x = 0;
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   145
if (retval) printf("fire it!\n");
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   146
return retval;
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   147
}
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   148
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   149
#endif
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   150
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
// end of keyhook.c ...
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152