static gint spi_dec_x11_get_keycode (SpiDEController *controller, gint keysym, gchar *key_str, gboolean fix, guint *modmask) { KeyCode keycode = 0; if (key_str && key_str[0]) keysym = XStringToKeysym(key_str); keycode = XKeysymToKeycode (spi_get_display (), (KeySym) keysym); if (!keycode && fix) { DEControllerPrivateData *priv = controller->priv; /* if there's no keycode available, fix it */ if (replace_map_keysym (priv, priv->reserved_keycode, keysym)) { keycode = priv->reserved_keycode; /* * queue a timer to restore the old keycode. Ugly, but required * due to races / asynchronous X delivery. * Long-term fix is to extend the X keymap here instead of replace entries. */ priv->reserved_reset_timeout = g_timeout_add (500, spi_dec_reset_reserved, priv); } if (modmask) *modmask = 0; return keycode; } if (modmask) *modmask = keysym_mod_mask (keysym, keycode); return keycode; }
static void add_sequence(char *rest, char *mapname) { KeySym keysym; key_translation *tr, **prev_next; size_t chars; char keyname[KEYMAP_MAX_LINE_LENGTH]; /* Skip over whitespace after the sequence keyword */ chars = strspn(rest, " \t"); rest += chars; /* Fetch the keysym name */ chars = strcspn(rest, " \t\0"); STRNCPY(keyname, rest, chars + 1); rest += chars; keysym = XStringToKeysym(keyname); if (keysym == NoSymbol) { DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname, mapname)); return; } DEBUG_KBD(("Adding sequence for keysym (0x%lx, %s) -> ", keysym, keyname)); free_key_translation(keymap[keysym & KEYMAP_MASK]); prev_next = &keymap[keysym & KEYMAP_MASK]; while (*rest) { /* Skip whitespace */ chars = strspn(rest, " \t"); rest += chars; /* Fetch the keysym name */ chars = strcspn(rest, " \t\0"); STRNCPY(keyname, rest, chars + 1); rest += chars; keysym = XStringToKeysym(keyname); if (keysym == NoSymbol) { DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname, mapname)); return; } /* Allocate space for key_translation structure */ tr = (key_translation *) xmalloc(sizeof(key_translation)); memset(tr, 0, sizeof(key_translation)); *prev_next = tr; prev_next = &tr->next; tr->seq_keysym = keysym; DEBUG_KBD(("0x%x, ", (unsigned int) keysym)); } DEBUG_KBD(("\n")); }
static int get_screen_selection(void) { static KeyCode lshift_code, rshift_code; static int first_time = 1; char keys[32]; if (first_time) { first_time = 0; lshift_code = XKeysymToKeycode(GDK_WINDOW_XDISPLAY(bm.win), XStringToKeysym("Shift_L")); rshift_code = XKeysymToKeycode(GDK_WINDOW_XDISPLAY(bm.win), XStringToKeysym("Shift_R")); } XQueryKeymap(GDK_WINDOW_XDISPLAY(bm.win), keys); #if 0 if (0) { /* debug */ int i = 0; printf("lshift_code = 0x%x (index = %d, bit = %d\n", lshift_code, lshift_code >> 3, lshift_code % 8); printf("rshift_code = 0x%x (index = %d, bit = %d\n", rshift_code, rshift_code >> 3, rshift_code % 8); for (i = 0; i < (sizeof(keys) / sizeof(keys[0])); i++) { if (0 == (i % 8)) { printf("\n%2d:", i); } printf(" %2d", keys[i]); } printf("\n"); }
int main() { Display *xdpy; Window root; char *display_name = NULL; int ver; if ( (display_name = getenv("DISPLAY")) == (void *)NULL) { fprintf(stderr, "Error: DISPLAY environment variable not set\n"); exit(1); } printf("Display: %s\n", display_name); if ( (xdpy = XOpenDisplay(display_name)) == NULL) { fprintf(stderr, "Error: Can't open display: %s", display_name); exit(1); } if (XTestQueryExtension(xdpy, &ver, &ver, &ver, &ver) != True) { printf("No xtest :(\n"); return 1; } { int control, alt, key_l, key_two, del; control = XKeysymToKeycode(xdpy, XStringToKeysym("Control_L")); alt = XKeysymToKeycode(xdpy, XStringToKeysym("Alt_L")); key_l = XKeysymToKeycode(xdpy, XStringToKeysym("L")); key_two = XKeysymToKeycode(xdpy, XStringToKeysym("2")); del = XKeysymToKeycode(xdpy, XStringToKeysym("BackSpace")); printf("%d %d %d %d\n", control, alt, key_l, key_two); return; XTestFakeKeyEvent(xdpy, alt, True, CurrentTime); XTestFakeKeyEvent(xdpy, key_two, True, CurrentTime); XTestFakeKeyEvent(xdpy, key_two, False, CurrentTime); XTestFakeKeyEvent(xdpy, alt, False, CurrentTime); XTestFakeKeyEvent(xdpy, control, True, 100); XTestFakeKeyEvent(xdpy, key_l, True, CurrentTime); XTestFakeKeyEvent(xdpy, key_l, False, CurrentTime); XTestFakeKeyEvent(xdpy, control, False, CurrentTime); XTestFakeMotionEvent(xdpy, 0, 50, 55, CurrentTime); //XTestFakeButtonEvent(xdpy, 1, True, CurrentTime); //XTestFakeButtonEvent(xdpy, 1, False, CurrentTime); XTestFakeKeyEvent(xdpy, del, True, 50); XTestFakeKeyEvent(xdpy, del, False, CurrentTime); XTestFakeButtonEvent(xdpy, 2, True, CurrentTime); XTestFakeButtonEvent(xdpy, 2, False, CurrentTime); XFlush(xdpy); } return 0; }
/* * Set key character that will show/hide Stjerm */ void set_key(char *v) { _key = 0; v[0] = tolower(v[0]); _key = XStringToKeysym(v); if (!_key) { v[0] = toupper(v[0]); _key = XStringToKeysym(v); } }
int X11KeySymToKeycode(QString key) { int tempcode = 0; #if defined (Q_OS_UNIX) Display* display = X11Info::display(); if (key.length() > 0) { tempcode = XKeysymToKeycode(display, XStringToKeysym(key.toUtf8().data())); } #elif defined (Q_OS_WIN) if (key.length() > 0) { tempcode = WinInfo::getVirtualKey(key); if (tempcode <= 0 && key.length() == 1) { //qDebug() << "KEY: " << key; //int oridnal = key.toUtf8().constData()[0]; int ordinal = QVariant(key.toUtf8().constData()[0]).toInt(); tempcode = VkKeyScan(ordinal); int modifiers = tempcode >> 8; tempcode = tempcode & 0xff; if ((modifiers & 1) != 0) tempcode |= VK_SHIFT; if ((modifiers & 2) != 0) tempcode |= VK_CONTROL; if ((modifiers & 4) != 0) tempcode |= VK_MENU; //tempcode = VkKeyScan(QVariant(key.constData()).toInt()); //tempcode = OemKeyScan(key.toUtf8().toInt()); //tempcode = OemKeyScan(ordinal); }
static KeyCode grab_key(char *keystring) { KeySym sym; KeyCode code; gint i; if ((sym = XStringToKeysym(keystring)) == NoSymbol) return 0; if ((code = XKeysymToKeycode(GDK_DISPLAY(), sym)) == 0) return 0; gdk_error_trap_push(); for (i = 0; i < ScreenCount(GDK_DISPLAY()); i++) { XGrabKey(GDK_DISPLAY(), code, AnyModifier, RootWindow(GDK_DISPLAY(),i), 1, GrabModeAsync, GrabModeAsync); } gdk_flush(); if (gdk_error_trap_pop()) { g_warning("Couldn't grab %s: another client may already have done so", keystring); return 0; } return code; }
KeyCombo stringToKeyCombo(std::string str, Display* display) { KeyCombo combo; combo.keySym = 0; combo.mask = 0U; if (str.empty()) { combo.keySym = XK_VoidSymbol; return combo; } bool hasPrimaryKey = false; // If no key is specified, produce an error for (auto token : split(str, '+')) { if (token == "Shift") { combo.mask |= ShiftMask; } else if (token == "Ctrl") { combo.mask |= ControlMask; } else if (token == "Alt") { combo.mask |= Mod1Mask; } else { if (hasPrimaryKey) throw new std::runtime_error( "Invalid key combination: two primary keys!"); combo.keySym = XStringToKeysym(token.c_str()); if (combo.keySym == NoSymbol) throw new std::runtime_error( "Invalid key combination: invalid key!"); combo.keyCode = XKeysymToKeycode(display, combo.keySym); hasPrimaryKey = true; } } if (!hasPrimaryKey) throw new std::runtime_error( "Invalid key combination: no primary key specified!"); return combo; }
void CwmPaste:: pasteChar(CwmWMWindow *window, int c) { CwmUserWindow *user = window->getUser(); if (! user) return; char key_string[2]; key_string[0] = c; key_string[1] = '\0'; KeySym keysym = XStringToKeysym(key_string); if (keysym == NoSymbol) return; uint keycode = CwmMachineInst->keysymToKeycode(keysym); CwmMachineInst->sendKeyPressedEvent(user->getXWindow()->getXWin(), user->getX(), user->getY(), keycode); CwmMachineInst->sendKeyReleasedEvent(user->getXWindow()->getXWin(), user->getX(), user->getY(), keycode); }
int x11_parse_key(const char *str, KeySym *key, unsigned int *mask) { /** \todo better parsing */ int c, s; *mask = 0; c = s = 0; while (str[c] != '\0') { if (str[c] == '<') s = c; else if (str[c] == '>') { if (!strncmp(&str[s], "<Ctrl>", c - s)) *mask |= X11_KEY_CTRL; else if (!strncmp(&str[s], "<Shift>", c - s)) *mask |= X11_KEY_SHIFT; else return EINVAL; s = c + 1; } c++; } *key = XStringToKeysym(&str[s]); if (!(*key)) return EINVAL; return 0; }
EAPI int ecore_x_test_fake_key_press(const char *key) { #ifdef ECORE_XTEST KeyCode keycode = 0; KeySym keysym = 0; int shift = 0; LOGFN(__FILE__, __LINE__, __FUNCTION__); if (!strncmp(key, "Keycode-", 8)) keycode = atoi(key + 8); else { keysym = XStringToKeysym(key); if (keysym == NoSymbol) return 0; keycode = XKeysymToKeycode(_ecore_x_disp, keysym); if (XKeycodeToKeysym(_ecore_x_disp, keycode, 0) != keysym) { if (XKeycodeToKeysym(_ecore_x_disp, keycode, 1) == keysym) shift = 1; else keycode = 0; } else shift = 0; } if (keycode == 0) { static int mod = 0; KeySym *keysyms; int keycode_min, keycode_max, keycode_num; int i; XDisplayKeycodes(_ecore_x_disp, &keycode_min, &keycode_max); keysyms = XGetKeyboardMapping(_ecore_x_disp, keycode_min, keycode_max - keycode_min + 1, &keycode_num); mod = (mod + 1) & 0x7; i = (keycode_max - keycode_min - mod - 1) * keycode_num; keysyms[i] = keysym; XChangeKeyboardMapping(_ecore_x_disp, keycode_min, keycode_num, keysyms, (keycode_max - keycode_min)); XFree(keysyms); XSync(_ecore_x_disp, False); keycode = keycode_max - mod - 1; } if (shift) XTestFakeKeyEvent(_ecore_x_disp, XKeysymToKeycode(_ecore_x_disp, XK_Shift_L), 1, 0); XTestFakeKeyEvent(_ecore_x_disp, keycode, 1, 0); XTestFakeKeyEvent(_ecore_x_disp, keycode, 0, 0); if (shift) XTestFakeKeyEvent(_ecore_x_disp, XKeysymToKeycode(_ecore_x_disp, XK_Shift_L), 0, 0); return 1; #else return 0; #endif }
/* ** Part of dialog mnemonic processing. Search the widget tree under w ** for widgets with mnemonics. When found, add a passive grab to the ** dialog widget for the mnemonic character, thus directing mnemonic ** events to the dialog widget. */ static void addMnemonicGrabs(Widget dialog, Widget w) { char mneString[2]; WidgetList children; int numChildren, i, isMenu; KeySym mnemonic = '\0'; unsigned char rowColType; if (XtIsComposite(w)) { if (XtClass(w) == xmRowColumnWidgetClass) { XtVaGetValues(w, XmNrowColumnType, &rowColType, 0); isMenu = rowColType != XmWORK_AREA; } else isMenu = False; if (!isMenu) { XtVaGetValues(w, XmNchildren, &children, XmNnumChildren, &numChildren, 0); for (i=0; i<numChildren; i++) addMnemonicGrabs(dialog, children[i]); } } else { XtVaGetValues(w, XmNmnemonic, &mnemonic, 0); if (mnemonic != '\0') { mneString[0] = mnemonic; mneString[1] = '\0'; XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog), XStringToKeysym(mneString)), Mod1Mask, True, GrabModeAsync, GrabModeAsync); } } }
Condition StrToCondition(char *str) { KeySym keysym; KeyCode keycode; Condition condition; if (str[0]=='-' && str[1]==0) return 0; if (str[0]>='0' && str[0]<='9') { /* keycode number is specified */ return atoi(str); } else if (str[0]=='\'' || str[0]=='"') { /* asking to convert a keysym text to keycode */ str[strlen(str)-1]=0; str=&str[1]; keysym=XStringToKeysym(str); if (keysym==0) { printf("StrToCondition: '%s' does not map to a keysym!\n",str); } keycode=XKeysymToKeycode(disp, keysym); DEBUG(D_CALLS) printf("StrToCondition: '%s' -> %d -> %d\n",str,keysym,keycode); return (keycode); } else { /* otherwise look up the code in a special table */ condition=StrToCondition_FromTable(str); if (condition==0) {printf("StrToCondition: '%s' not found in table.\n",str);} DEBUG(D_CALLS) printf("StrToCondition: '%s' -> %d\n",str,condition); return StrToCondition_FromTable(str); } }
/** * Initialize X connection, establish grab. */ Display* initX(const char* keyName, int keyModifier, int* keyCode) { KeySym sym = XStringToKeysym(keyName); if (sym == NoSymbol) { fprintf(stderr, "ERROR: Unknown key: %s\n", keyName); exit(2); } Display* display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr, "ERROR: Could not open display.\n"); exit(3); } *keyCode = XKeysymToKeycode(display, sym); Window rootWindow = DefaultRootWindow(display); initMasks(display); Bool detectableAutoRepeatSupported; XkbSetDetectableAutoRepeat(display, True, &detectableAutoRepeatSupported); if (!detectableAutoRepeatSupported) { fprintf(stderr, "ERROR: Detectable auto repeat is not supported.\n"); exit(4); } // Grab grabKey(display, rootWindow, *keyCode, keyModifier); // Enable events XAllowEvents(display, AsyncBoth, CurrentTime); XSelectInput(display, rootWindow, KeyPressMask | KeyReleaseMask); return display; }
static void add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) { KeySym keysym; key_translation *tr; keysym = XStringToKeysym(keyname); if (keysym == NoSymbol) { DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring)\n", keyname, mapname)); return; } DEBUG_KBD(("Adding translation, keysym=0x%x, scancode=0x%x, " "modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers)); tr = (key_translation *) xmalloc(sizeof(key_translation)); memset(tr, 0, sizeof(key_translation)); tr->scancode = scancode; tr->modifiers = modifiers; free_key_translation(keymap[keysym & KEYMAP_MASK]); keymap[keysym & KEYMAP_MASK] = tr; return; }
static void add_hot_key(const char* keyname, const char* command) { char* copy = strdup(keyname); char* unmodified = strrchr(copy, '-'); unsigned int modifiers = 0; if (unmodified == NULL) { unmodified = copy; } else { *unmodified = 0; ++ unmodified; modifiers = parse_modifiers(copy, keyname); } HotKey* new_key = new HotKey; new_key->keysym = XStringToKeysym(unmodified); new_key->modifiers = modifiers; new_key->command = strdup(command); new_key->next = hotkeys; hotkeys = new_key; XSynchronize(dpy, True); attempting_to_grab = keyname; XSetErrorHandler(report_key_grab_error); for (int screen = 0; screen < screen_count; ++screen) { Window root = RootWindow(dpy, screen); XGrabKey(dpy, XKeysymToKeycode(dpy, new_key->keysym), modifiers, root, False, GrabModeAsync, GrabModeAsync); } XSetErrorHandler(NULL); free(copy); }
static void handle_events(Display *dpy, Window window, int width, int height) { XEvent xev; KeyCode quit_code = XKeysymToKeycode (dpy, XStringToKeysym("Q")); XNextEvent (dpy, &xev); while (1) { XNextEvent (dpy, &xev); switch (xev.type) { case KeyPress: if (xev.xkey.keycode == quit_code) { return; } break; case ConfigureNotify: width = xev.xconfigure.width; height = xev.xconfigure.height; break; case Expose: if (xev.xexpose.count == 0) { draw (dpy, window, width, height); return; } break; } } }
KeySym grab_that_key(char *opt, unsigned int numlockmask) { unsigned int modmask = 0; KeySym keysym; if (strstr(opt, "Control")) modmask = modmask | ControlMask; if (strstr(opt, "Alt")) modmask = modmask | Mod1Mask; if (strstr(opt, "Win")) modmask = modmask | Mod4Mask; if (strstr(opt, "None")) modmask = 0; opt = strrchr(opt, '+'); keysym = XStringToKeysym(++opt); XGrabKey(dpy, XKeysymToKeycode(dpy, keysym), modmask, root, True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, XKeysymToKeycode(dpy, keysym), LockMask | modmask, root, True, GrabModeAsync, GrabModeAsync); if (numlockmask) { XGrabKey(dpy, XKeysymToKeycode(dpy, keysym), numlockmask | modmask, root, True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, XKeysymToKeycode(dpy, keysym), numlockmask | LockMask | modmask, root, True, GrabModeAsync, GrabModeAsync); } return keysym; }
static void add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) { KeySym keysym; key_translation_entry *entry; keysym = XStringToKeysym(keyname); if (keysym == NoSymbol) { DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring)\n", keyname, mapname)); return; } DEBUG_KBD(("Adding translation, keysym=0x%x, scancode=0x%x, " "modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers)); /* Make a new entry in the table */ entry = new_key_translation_entry(keysym); /* And add the new translation to it */ entry->tr = (key_translation *) xmalloc(sizeof(key_translation)); memset(entry->tr, 0, sizeof(key_translation)); entry->tr->scancode = scancode; entry->tr->modifiers = modifiers; return; }
static void luaA_keystore(lua_State *L, int ud, const char *str, ssize_t len) { keyb_t *key = luaA_checkudata(L, ud, &key_class); if(len) { if(*str != '#') { key->keysym = XStringToKeysym(str); if(!key->keysym) { if(len == 1) key->keysym = *str; else warn("there's no keysym named \"%s\"", str); } key->keycode = 0; } else { key->keycode = atoi(str + 1); key->keysym = 0; } luaA_object_emit_signal(L, ud, "property::key", 0); } }
/* keyboard */ void keyboard_set_state (const char* key, int state) { Display* display = XOpenDisplay(NULL); KeySym sym = XStringToKeysym(key); KeyCode keycode = XKeysymToKeycode(display, sym); XTestFakeKeyEvent(display, keycode, state, 0); XCloseDisplay(display); }
void ParseKeyBinding( ConfigItem *item, FreeStorageElem *func_elem, struct FuncKey **keyboard ) { KeySym keysym; KeyCode keycode; int context, mods ; int min = 0, max = 0 ; if( item == NULL ) return ; item->ok_to_free = 1; if( item == NULL || func_elem == NULL || keyboard == NULL ) return ; if( func_elem->term == NULL || func_elem->term->type != TT_FUNCTION ) return ; /* * Don't let a 0 keycode go through, since that means AnyKey to the * XGrabKey call in GrabKeys(). */ if( (keysym = XStringToKeysym (item->data.binding.sym)) == NoSymbol || (keycode = XKeysymToKeycode (dpy, keysym)) == 0) return ; XDisplayKeycodes (dpy, &min, &max); for (keycode = min; keycode <= max; keycode++) if (XKeycodeToKeysym (dpy, keycode, 0) == keysym) break; if (keycode > max) return ; context = item->data.binding.context ; mods = item->data.binding.mods ; if( !ReadConfigItem( item, func_elem ) ) return ; if( item->data.function ) { /* gotta add it to the keyboard hash */ FuncKey *tmp ; tmp = (FuncKey *) safecalloc (1, sizeof (FuncKey)); tmp->next = *keyboard; *keyboard = tmp ; tmp->name = mystrdup(item->data.binding.sym); tmp->keycode = keycode; tmp->cont = context; tmp->mods = mods; tmp->fdata = item->data.function; item->data.function = NULL ; } item->ok_to_free = (item->data.function != NULL); }
static KeyCode keyToKeycode(const char *key) { KeySym keySym = XStringToKeysym(key); if(keySym == NoSymbol) return keyToKeycode("space"); return XKeysymToKeycode(QX11Info::display(), keySym); }
int main(int argc, const char **argv) { if (!(dpy=XOpenDisplay(0x0))) return 1; scr = DefaultScreen(dpy); root = RootWindow(dpy,scr); sw = DisplayWidth(dpy,scr); sh = DisplayHeight(dpy,scr); if (argc > 1) { if (argv[1][0] == '-' && argv[1][1] == 'h') printf("IOCANE: Copyright 2012, Jesse McClure\nSee `man iocane` for commands and examples.\n"); if (argv[1][0] == '-' && argv[1][1] == '\0') stdinmode(argc,argv); else scriptmode(argc,argv); XCloseDisplay(dpy); return 0; } /* no args -> interactive mode: */ Key *keys = NULL; char *line = (char *) calloc(MAXLINE+MAXSYMLEN+2,sizeof(char)); char keystring[MAXSYMLEN]; KeySym keysym; chdir(getenv("HOME")); FILE *rcfile = fopen(".iocanerc","r"); if (rcfile == NULL) fopen("/usr/share/iocane/iocanerc","r"); if (rcfile == NULL) { fprintf(stderr,"IOCANE: no iocanerc file found.\n"); XCloseDisplay(dpy); return 0; } int i = 0; while (fgets(line,MAXLINE+MAXSYMLEN+2,rcfile) != NULL) { if (line[0] == '#' || line[0] == '\n') continue; strncpy(keystring,line,MAXSYMLEN); *strchr(keystring,' ') = '\0'; if ( (keysym=XStringToKeysym(keystring)) == NoSymbol ) continue; keys = realloc(keys,(i+1) * sizeof(Key)); keys[i].key = XKeysymToKeycode(dpy,keysym); keys[i].command = (char *) calloc(strlen(line) - strlen(keystring),sizeof(char)); strcpy(keys[i].command,strchr(line,' ')+1); XGrabKey(dpy,keys[i].key,0,root,True,GrabModeAsync,GrabModeAsync); XGrabKey(dpy,keys[i++].key,LockMask,root,True,GrabModeAsync,GrabModeAsync); } int keycount = i; free(line); fclose(rcfile); XEvent ev; XKeyEvent *e; while (running && !XNextEvent(dpy,&ev)) if (ev.type == KeyPress) { e = &ev.xkey; for (i = 0; i < keycount; i++) if (e->keycode == keys[i].key && keys[i].command) command(keys[i].command); } for (i = 0; i < keycount; i++) free(keys[i].command); free(keys); XCloseDisplay(dpy); return 0; }
void sendChar(char c) { KeySym ks, sks, *kss, ksl, ksu; KeyCode kc, skc; int Delay = 10; int syms; #ifdef DEBUG int i; #endif sks=XK_Shift_L; ks=XStringToKeysym(chartbl[0][(unsigned char)c]); if ( ( kc = XKeysymToKeycode ( RemoteDpy, ks ) ) == 0 ) { std::cerr << "No keycode on remote display found for char: " << c << std::endl; return; } if ( ( skc = XKeysymToKeycode ( RemoteDpy, sks ) ) == 0 ) { std::cerr << "No keycode on remote display found for XK_Shift_L!" << std::endl; return; } kss=XGetKeyboardMapping(RemoteDpy, kc, 1, &syms); if (!kss) { std::cerr << "XGetKeyboardMapping failed on the remote display (keycode: " << kc << ")" << std::endl; return; } for (; syms && (!kss[syms-1]); syms--); if (!syms) { std::cerr << "XGetKeyboardMapping failed on the remote display (no syms) (keycode: " << kc << ")" << std::endl; XFree(kss); return; } XConvertCase(ks,&ksl,&ksu); #ifdef DEBUG std::cout << "kss: "; for (i=0; i<syms; i++) std::cout << kss[i] << " "; std::cout << "(" << ks << " l: " << ksl << " h: " << ksu << ")" << std::endl; #endif if (ks==kss[0] && (ks==ksl && ks==ksu)) sks=NoSymbol; if (ks==ksl && ks!=ksu) sks=NoSymbol; if (sks!=NoSymbol) XTestFakeKeyEvent ( RemoteDpy, skc, True, Delay ); XTestFakeKeyEvent ( RemoteDpy, kc, True, Delay ); XFlush ( RemoteDpy ); XTestFakeKeyEvent ( RemoteDpy, kc, False, Delay ); if (sks!=NoSymbol) XTestFakeKeyEvent ( RemoteDpy, skc, False, Delay ); XFlush ( RemoteDpy ); XFree(kss); }
void grabkeys() { /* For now, TODO: add shortcuts. */ printf("wimp: grabbing keys\n"); XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("Up")), MODKEY|ShiftMask, root, True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("Down")), MODKEY|ShiftMask, root, True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("Left")), MODKEY|ShiftMask, root, True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("Right")), MODKEY|ShiftMask, root, True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("t")), MODKEY, root, True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("q")), MODKEY, root, True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("c")), MODKEY, root, True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("o")), MODKEY, root, True, GrabModeAsync, GrabModeAsync); }
// convert a Mod+key arg to mod mask and keysym void x11_parse_key ( char *combo, unsigned int *mod, KeySym *key ) { unsigned int modmask = 0; if ( strcasestr ( combo, "shift" ) ) { modmask |= ShiftMask; } if ( strcasestr ( combo, "control" ) ) { modmask |= ControlMask; } if ( strcasestr ( combo, "mod1" ) ) { modmask |= Mod1Mask; } if ( strcasestr ( combo, "alt" ) ) { modmask |= Mod1Mask; } if ( strcasestr ( combo, "mod2" ) ) { modmask |= Mod2Mask; } if ( strcasestr ( combo, "mod3" ) ) { modmask |= Mod3Mask; } if ( strcasestr ( combo, "mod4" ) ) { modmask |= Mod4Mask; } if ( strcasestr ( combo, "mod5" ) ) { modmask |= Mod5Mask; } *mod = modmask; // Skip modifier (if exist) and parse key. char i = strlen ( combo ); while ( i > 0 && !strchr ( "-+", combo[i - 1] ) ) { i--; } KeySym sym = XStringToKeysym ( combo + i ); if ( sym == NoSymbol || ( !modmask && ( strchr ( combo, '-' ) || strchr ( combo, '+' ) ) ) ) { // TODO popup fprintf ( stderr, "sorry, cannot understand key combination: %s\n", combo ); } *key = sym; }
void switcher_button_switch_layout(SwitcherButton *self, int langN) { if (self->priv->current == langN) return; if (self->priv->model == N810) { // Simulate Ctrl+Chr sequence GdkDisplay* gdkDisplay = gdk_display_get_default(); if (gdkDisplay == 0) return; Display *dpy = (Display*)gdk_x11_display_get_xdisplay(gdkDisplay); if (dpy == 0) return; KeySym Control_R_Sym = XStringToKeysym("Control_R"); KeySym Multi_key_Sym = XStringToKeysym("Multi_key"); if (Control_R_Sym == 0 || Multi_key_Sym == 0) return; KeyCode Control_R = XKeysymToKeycode(dpy, Control_R_Sym); KeyCode Multi_key = XKeysymToKeycode(dpy, Multi_key_Sym); if (Control_R == 0 || Multi_key == 0) return; XTestFakeKeyEvent(dpy, Control_R, True, CurrentTime); XTestFakeKeyEvent(dpy, Multi_key, True, CurrentTime); XTestFakeKeyEvent(dpy, Multi_key, False, CurrentTime); XTestFakeKeyEvent(dpy, Control_R, False, CurrentTime); } if (self->priv->model == N800) gconf_client_set_int(self->priv->gconfClient, GCONF_CURRENT_2008, langN, 0); if (self->priv->model == N770) gconf_client_set_bool(self->priv->gconfClient, GCONF_CURRENT_2006, langN == 0, 0); if (self->priv->model == N900) { } }
KeyCode char2KeyCode(char c, bool &need_shift){ char buf[2]; buf[0]=c;buf[1]='\0'; KeySym sym = XStringToKeysym(buf); need_shift=false; KeySym ksl, ksu; XConvertCase(sym, &ksl, &ksu); if(sym==ksu && ksl!=ksu) need_shift=true; KeyCode kc = XKeysymToKeycode(display, sym); return kc; }
static void config_keybind(void) { int i, n; size_t j; struct conf_sec *sec, **ks; struct opt_type *opt; char *cmd; struct keybind *k; /* [keys] */ sec = fetch_section_first(NULL, "keys"); ks = fetch_section(sec, "key"); n = fetch_section_count(ks); SLIST_INIT(&W->h.keybind); /* [key] */ for(i = 0; i < n; ++i) { k = (struct keybind*)xcalloc(1, sizeof(struct keybind)); /* mod = {} */ opt = fetch_opt(ks[i], "", "mod"); for(j = k->mod = 0; j < fetch_opt_count(opt); ++j) k->mod |= modkey_keysym(opt[j].str); free(opt); /* key = */ k->keysym = XStringToKeysym(fetch_opt_first(ks[i], "None", "key").str); /* func = */ if(!(k->func = uicb_name_func(fetch_opt_first(ks[i], "", "func").str))) { warnxl("configuration: Unknown Function \"%s\".", fetch_opt_first(ks[i], "", "func").str); k->func = uicb_spawn; } /* cmd = */ if((cmd = fetch_opt_first(ks[i], "", "cmd").str)) k->cmd = xstrdup(cmd); SLIST_INSERT_HEAD(&W->h.keybind, k, next); } wmfs_grab_keys(); free(ks); }