XQUERYDEVICESTATE(3)

πŸ’– XQUERYDEVICESTATE πŸ’–

okay bestie, gather round, because we're reading the XQUERYDEVICESTATE(3) page together and honestly? it's giving "short and powerful". this one is literally about querying the state of an extension input device. so like, "what's my keyboard doing right now", "is that button pressed", "where's the valuator at". obsessed. ✨


✨ NAME ✨

XQueryDeviceState β€” query the state of an extension input device. πŸŽ€


🌸 SYNOPSIS 🌸

#include <X11/extensions/XInput.h>

XDeviceState* XQueryDeviceState( Display *display,
                                 XDevice *device);
  • display β€” bestie, this is the connection to the X server. that's it, that's the whole thing.
  • device β€” the device whose state we're about to go snooping on. πŸ‘€

πŸ¦‹ DESCRIPTION πŸ¦‹

so the XQueryDeviceState request queries the state of an input device. the current state of keys and buttons (up or down, no in-between, we love a binary) and valuators (their current value) on the device gets reported by this request. πŸ’…

every key or button is represented by a bit in the XDeviceState structure that gets returned. and the valuators on the device report 0 if they're reporting relative information, and the current value if they're reporting absolute information. periodt.

XQueryDeviceState can generate a BadDevice error. (more on that below, don't panic 🫢)

Structures 🧚

the XDeviceState structure contains:

typedef struct {
    XID device_id;
    int num_classes;
    XInputClass *data;
} XDeviceState;

the XValuatorState structure contains:

typedef struct {
    unsigned char class;
    unsigned char length;
    unsigned char num_valuators;
    unsigned char mode;
    int *valuators;
} XValuatorState;

the XKeyState structure contains:

typedef struct {
    unsigned char class;
    unsigned char length;
    short     num_keys;
    char keys[32];
} XKeyState;

the XButtonState structure contains:

typedef struct {
    unsigned char class;
    unsigned char length;
    short     num_buttons;
    char buttons[32];
} XButtonState;

πŸ’€ DIAGNOSTICS πŸ’€

  • BadDevice β€” an invalid device was specified 😭. the specified device does not exist, or it has not been opened by this client via XOpenInputDevice. this error may also occur if some other client has caused the specified device to become the X keyboard or X pointer device via the XChangeKeyboardDevice or XChangePointerDevice requests. so basically, somebody else snatched it. rude. πŸ’…

lowkey the whole vibe of this page is "ask the device how it's feeling, get structs back". no cap.

and that's the tea, bestie πŸ“ this was XQUERYDEVICESTATE(3), dated 05/18/2026 β€” main character energy from start to finish, slay πŸ’–βœ¨πŸ‘‘

πŸ“¦ where this page comes from