static SCM scm_bind_key(SCM mod_mask, SCM key, SCM proc) { xcb_keysym_t keysym; if (scm_is_true(scm_number_p(key))) keysym = scm_to_uint32(key); else if (scm_is_true(scm_string_p(key))) { scm_dynwind_begin(0); char *c_key = scm_to_locale_string(key); scm_dynwind_free(c_key); keysym = get_keysym(c_key); scm_dynwind_end(); } else return SCM_UNSPECIFIED; bind_key(scm_to_uint16(mod_mask), keysym, proc); return SCM_UNSPECIFIED; }
platform::scancode keyboard::get_scancode( xcb_keycode_t code ) { xcb_keysym_t key = get_keysym( code, 0 ); if ( key == XCB_NO_SYMBOL ) return platform::scancode::KEY_UNKNOWN; if ( key >= XK_a && key <= XK_z ) return static_cast<platform::scancode>( static_cast<uint32_t>(platform::scancode::KEY_A) + ( key - XK_a ) ); if ( key >= XK_0 && key <= XK_9 ) return static_cast<platform::scancode>( static_cast<uint32_t>(platform::scancode::KEY_0) + ( key - XK_0 ) ); auto c = sym2code.find( key ); if ( c != sym2code.end() ) return c->second; std::cout << "KEYSYM = " << key << std::endl; return platform::scancode::KEY_UNKNOWN; }
static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, const char *language, kbd_layout_t * k) { FILE *f; char * filename; char line[1024]; int len; filename = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language); if (!k) k = g_malloc0(sizeof(kbd_layout_t)); if (!(filename && (f = fopen(filename, "r")))) { fprintf(stderr, "Could not read keymap file: '%s'\n", language); return NULL; } g_free(filename); for(;;) { if (fgets(line, 1024, f) == NULL) break; len = strlen(line); if (len > 0 && line[len - 1] == '\n') line[len - 1] = '\0'; if (line[0] == '#') continue; if (!strncmp(line, "map ", 4)) continue; if (!strncmp(line, "include ", 8)) { parse_keyboard_layout(table, line + 8, k); } else { char *end_of_keysym = line; while (*end_of_keysym != 0 && *end_of_keysym != ' ') end_of_keysym++; if (*end_of_keysym) { int keysym; *end_of_keysym = 0; keysym = get_keysym(table, line); if (keysym == 0) { // fprintf(stderr, "Warning: unknown keysym %s\n", line); } else { const char *rest = end_of_keysym + 1; char *rest2; int keycode = strtol(rest, &rest2, 0); if (rest && strstr(rest, "numlock")) { add_to_key_range(&k->keypad_range, keycode); add_to_key_range(&k->numlock_range, keysym); //fprintf(stderr, "keypad keysym %04x keycode %d\n", keysym, keycode); } if (rest && strstr(rest, "shift")) keycode |= SCANCODE_SHIFT; if (rest && strstr(rest, "altgr")) keycode |= SCANCODE_ALTGR; if (rest && strstr(rest, "ctrl")) keycode |= SCANCODE_CTRL; add_keysym(line, keysym, keycode, k); if (rest && strstr(rest, "addupper")) { char *c; for (c = line; *c; c++) *c = toupper(*c); keysym = get_keysym(table, line); if (keysym) add_keysym(line, keysym, keycode | SCANCODE_SHIFT, k); } } } } } fclose(f); return k; }
void handle_x_event ( XEvent& event, GtkWidget* label ) { KeySym key; char completion_string_c[BUFSIZ]; int completion_word_index = 0; int completion_flag = FALSE; switch(event.type) { case KeyPress: key = get_keysym(&event); if((isalpha(key) || isspace(key) || ispunct(key) || key == XK_BackSpace) && key < 256){ XevieSendEvent(dpy, &event, XEVIE_UNMODIFIED); get_prediction(tolower(key), completion_string_c, FALSE, label); if(((key == ',') || (key == '.') || (key == '?') || (key == ';') || (key == ':')) && (completion_word_index == 0) && (completion_flag == TRUE)) { event.xkey.keycode = XKeysymToKeycode(dpy, XK_BackSpace); event.type = KeyPress; XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event); event.type = KeyRelease; XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event); event.type = KeyPress; XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event); event.type = KeyRelease; XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event); event.xkey.keycode = XKeysymToKeycode(dpy, key); event.type = KeyPress; XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event); event.type = KeyRelease; XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event); event.xkey.keycode = XKeysymToKeycode(dpy, XK_space); event.type = KeyPress; XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event); event.type = KeyRelease; XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event); } else if(isspace(key)) completion_word_index = 0; else completion_word_index++; completion_flag = FALSE; } // check for function keys else if(((key - XK_F1) >= 0) && ((key - XK_F1) <= no_suggestions-1)) { // inform presage that the prediction was successful. // and ask presage to predict next token get_prediction(tolower(key), completion_string_c, TRUE, label); char s[64]; printf("%d\n", completion_word_index ); // send the rest of the completion string and a ' ' to the client while(completion_string_c[completion_word_index] != '\0'){ s[0] = completion_string_c[completion_word_index]; s[1] = '\0'; event.xkey.keycode = XKeysymToKeycode(dpy, XStringToKeysym(s)); event.type = KeyPress; XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event); event.type = KeyRelease; XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event); event.xkey.time++; completion_word_index++; } completion_word_index = 0; completion_flag = TRUE; event.xkey.keycode = XKeysymToKeycode(dpy, XK_space); event.type = KeyPress; XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event); event.type = KeyRelease; XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event); } else { // anything else just send it to the client XevieSendEvent(dpy, &event, XEVIE_UNMODIFIED); completion_word_index = 0; completion_flag = FALSE; } break; case KeyRelease: XevieSendEvent(dpy, &event, XEVIE_UNMODIFIED); break; default: printf(" unknown event %x\n", event.type); break; } }
static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, const char *language, kbd_layout_t * k) { FILE *f; char file_name[1024]; char line[1024]; int len; snprintf(file_name, sizeof(file_name), "%s/keymaps/%s", bios_dir, language); if (!k) k = qemu_mallocz(sizeof(kbd_layout_t)); if (!(f = fopen(file_name, "r"))) { fprintf(stderr, "Could not read keymap file: '%s'\n", file_name); return 0; } for(;;) { if (fgets(line, 1024, f) == NULL) break; len = strlen(line); if (len > 0 && line[len - 1] == '\n') line[len - 1] = '\0'; if (line[0] == '#') continue; if (!strncmp(line, "map ", 4)) continue; if (!strncmp(line, "include ", 8)) { parse_keyboard_layout(table, line + 8, k); } else { char *end_of_keysym = line; while (*end_of_keysym != 0 && *end_of_keysym != ' ') end_of_keysym++; if (*end_of_keysym) { int keysym; *end_of_keysym = 0; keysym = get_keysym(table, line); if (keysym == 0) { // fprintf(stderr, "Warning: unknown keysym %s\n", line); } else { const char *rest = end_of_keysym + 1; char *rest2; int keycode = strtol(rest, &rest2, 0); if (rest && strstr(rest, "numlock")) { add_to_key_range(&k->keypad_range, keycode); add_to_key_range(&k->numlock_range, keysym); //fprintf(stderr, "keypad keysym %04x keycode %d\n", keysym, keycode); } /* if(keycode&0x80) keycode=(keycode<<8)^0x80e0; */ if (keysym < MAX_NORMAL_KEYCODE) { //fprintf(stderr,"Setting keysym %s (%d) to %d\n",line,keysym,keycode); k->keysym2keycode[keysym] = keycode; } else { if (k->extra_count >= MAX_EXTRA_COUNT) { fprintf(stderr, "Warning: Could not assign keysym %s (0x%x) because of memory constraints.\n", line, keysym); } else { #if 0 fprintf(stderr, "Setting %d: %d,%d\n", k->extra_count, keysym, keycode); #endif k->keysym2keycode_extra[k->extra_count]. keysym = keysym; k->keysym2keycode_extra[k->extra_count]. keycode = keycode; k->extra_count++; } } } } } } fclose(f); return k; }
static int parse_keyboard_layout(kbd_layout_t *k, const name2keysym_t *table, const char *language, Error **errp) { int ret; FILE *f; char * filename; char line[1024]; char keyname[64]; int len; filename = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language); trace_keymap_parse(filename); f = filename ? fopen(filename, "r") : NULL; g_free(filename); if (!f) { error_setg(errp, "could not read keymap file: '%s'", language); return -1; } for(;;) { if (fgets(line, 1024, f) == NULL) { break; } len = strlen(line); if (len > 0 && line[len - 1] == '\n') { line[len - 1] = '\0'; } if (line[0] == '#') { continue; } if (!strncmp(line, "map ", 4)) { continue; } if (!strncmp(line, "include ", 8)) { error_setg(errp, "keymap include files are not supported any more"); ret = -1; goto out; } else { int offset = 0; while (line[offset] != 0 && line[offset] != ' ' && offset < sizeof(keyname) - 1) { keyname[offset] = line[offset]; offset++; } keyname[offset] = 0; if (strlen(keyname)) { int keysym; keysym = get_keysym(table, keyname); if (keysym == 0) { /* warn_report("unknown keysym %s", line);*/ } else { const char *rest = line + offset + 1; int keycode = strtol(rest, NULL, 0); if (strstr(rest, "shift")) { keycode |= SCANCODE_SHIFT; } if (strstr(rest, "altgr")) { keycode |= SCANCODE_ALTGR; } if (strstr(rest, "ctrl")) { keycode |= SCANCODE_CTRL; } add_keysym(line, keysym, keycode, k); if (strstr(rest, "addupper")) { char *c; for (c = keyname; *c; c++) { *c = qemu_toupper(*c); } keysym = get_keysym(table, keyname); if (keysym) { add_keysym(line, keysym, keycode | SCANCODE_SHIFT, k); } } } } } } ret = 0; out: fclose(f); return ret; }