#include #include #include #include #include "qdebug.h" void key_code_for_symbol(xcb_keysym_t keysym, const xcb_setup_t *s) { int num_syms; const xkb_keysym_t *syms; struct xkb_rule_names xkb_names; struct xkb_state *xkb_state; struct xkb_keymap *xkb_keymap; struct xkb_context *xkb_context; memset(&xkb_names, 0, sizeof(xkb_names)); xkb_names.rules = "evdev"; xkb_names.model = "pc105"; xkb_names.layout = "us"; xkb_names.variant = ""; xkb_names.options = ""; xkb_context = xkb_context_new((xkb_context_flags)0); xkb_keymap = xkb_keymap_new_from_names(xkb_context, &xkb_names, XKB_MAP_COMPILE_PLACEHOLDER); xkb_state = xkb_state_new(xkb_keymap); bool found = false; for(xcb_keycode_t i = s->min_keycode; i && i < s->max_keycode; i++) { num_syms = xkb_state_key_get_syms(xkb_state, i, &syms); if (num_syms == 0) continue; for (int j = 0; j <= num_syms; j++) { if(syms[j] == keysym) { found = true; } } } if (found) qDebug() << "yes"; else qDebug() << "no"; } int main() { xcb_connection_t *conn; int screen; conn = xcb_connect(NULL, &screen); const xcb_setup_t *m_setup = xcb_get_setup(conn); const xcb_keysym_t symbols[] = { XK_Alt_L, XK_Meta_L, XK_Super_L, XK_Super_R, XK_Hyper_L, XK_Hyper_R, XK_Num_Lock, XK_Mode_switch, XK_Caps_Lock, }; const size_t numSymbols = sizeof symbols / sizeof *symbols; qDebug() << "### With xcb_key_symbols_t ###"; xcb_key_symbols_t *m_key_symbols = xcb_key_symbols_alloc(conn); xcb_keycode_t* modKeyCodes[numSymbols]; for (int i = 0; i < numSymbols; ++i) { modKeyCodes[i] = xcb_key_symbols_get_keycode(m_key_symbols, symbols[i]); } for (int z = 0; z < numSymbols; ++z) { qDebug() << "index : "<< z << " " << modKeyCodes[z]; } qDebug() << "### With libxkbcommon ###"; for (int i = 0; i < numSymbols; ++i) { key_code_for_symbol(symbols[i], m_setup); } }