static GdkEventKey * key_event_to_gdk (ClutterKeyEvent *event_clutter) { GdkDisplay *display = gdk_display_get_default (); GdkKeymap *keymap = gdk_keymap_get_for_display (display); GdkEventKey *event_gdk; event_gdk = (GdkEventKey *)gdk_event_new ((event_clutter->type == CLUTTER_KEY_PRESS) ? GDK_KEY_PRESS : GDK_KEY_RELEASE); event_gdk->window = window_for_actor ((ClutterActor *)event_clutter->stage); event_gdk->send_event = FALSE; event_gdk->time = event_clutter->time; /* This depends on ClutterModifierType and GdkModifierType being * identical, which they are currently. (They both match the X * modifier state in the low 16-bits and have the same extensions.) */ event_gdk->state = event_clutter->modifier_state; event_gdk->keyval = event_clutter->keyval; event_gdk->hardware_keycode = event_clutter->hardware_keycode; /* For non-proper non-XKB support, we'd need a huge cut-and-paste * from gdkkeys-x11.c; this is a macro that just shifts a few bits * out of state, so won't make the situation worse if the server * doesn't support XKB; we'll just end up with group == 0 */ event_gdk->group = XkbGroupForCoreState (event_gdk->state); gdk_keymap_translate_keyboard_state (keymap, event_gdk->hardware_keycode, event_gdk->state, event_gdk->group, &event_gdk->keyval, NULL, NULL, NULL); if (event_clutter->unicode_value) { /* This is not particularly close to what GDK does - event_gdk->string * is supposed to be in the locale encoding, and have control keys * as control characters, etc. See gdkevents-x11.c:translate_key_event(). * Hopefully no input method is using event.string. */ char buf[6]; event_gdk->length = g_unichar_to_utf8 (event_clutter->unicode_value, buf); event_gdk->string = g_strndup (buf, event_gdk->length); } event_gdk->is_modifier = key_is_modifier (event_gdk->keyval); return event_gdk; }
void fill_keyboard_report(USB_KeyboardReport_Data_t* keyboardReport) { uint8_t used_keycodes = 0; matrix_row_t row = 0; matrix_row_t col = 0; for (row = 0; row < MATRIX_ROWS && used_keycodes < MAX_KEYCODES; ++row) { for (col = 0; col < MATRIX_COLS && used_keycodes < MAX_KEYCODES; ++col) { if (matrix_switch_pressed_at(row, col)) { keycode_t key = keymap_key_at(row, col); check_for_layer_change_command(key); if (key_is_modifier(key)) { keyboardReport->Modifier |= key_to_modifier(key); } else { keyboardReport->KeyCode[used_keycodes] = key; ++used_keycodes; } } } } }