Re: key binding - function keys

From: Claude Lecommandeur (lecom@slhp1.epfl.ch)
Date: Mon Jul 28 1997 - 09:33:16 CEST


> Hello CTWM users,
>
> since those of you who have answered many ctwm questions with lots
> of X-expertise I thought I'd pose this query here.
>
> How do I go about finding the names of the keys of my keyboard
> so that I can bind functions to them in my .ctwmrc file?

   xev will do it. If you don't have it, I attach a little program
that can help.

>
> Also, is there a way to make the bindings or ctwm itself
> more application aware so that the app may interpret a key
> differently than ctwm? (I am just curious here.)

   You have to avoid clashes between ctwm and apps. In case of
clashes, ctwm wins.

    Claude.

----------------------------------------------------------------
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

main () {
    Display *dpy;
    int scrn;
    Window root, win;
    char *keyname;
    KeySym keysym;
    XEvent event;
    XKeyEvent *kevent;
    int status;

    dpy = XOpenDisplay (NULL);
    if (dpy == (Display*) 0) {
        fprintf (stderr, "Can't open display.\n");
        exit (1);
    }
    scrn = DefaultScreen (dpy);
    root = RootWindow (dpy, scrn);

    win = XCreateSimpleWindow (dpy, root, 200, 200, 300, 200, 1, 0, 1);
    XSelectInput (dpy, win, KeyPressMask);
    XMapWindow (dpy, win);

    while (!XNextEvent (dpy, &event)) {
        switch (event.type) {
            case KeyPress :
                kevent =(XKeyEvent*) &event;
                keysym = XLookupKeysym (kevent, 0);
                if (! keysym) {
                    fprintf (stderr, "error 1\n");
                    continue;
                }
                keyname = XKeysymToString (keysym);
                if (! keyname) {
                    fprintf (stderr, "error 2\n");
                    continue;
                }
                printf ("keycode = %d, name = %s\n", kevent->keycode, keyname);
                break;

            default:
                break;
        }
    }
}
-------------------------------------------------------------



This archive was generated by hypermail 2.1.2 : Sat Jun 22 2002 - 06:45:03 CEST