| 471 | } |
| 472 | |
| 473 | list<GdkEvent*> KeypressEventsHandler::CreateEventsForKey( |
| 474 | wchar_t key_to_emulate) |
| 475 | { |
| 476 | list<GdkEvent*> ret_list; |
| 477 | // First case - is it the NULL symbol? If so, reset modifiers and exit. |
| 478 | if (key_to_emulate == gNullKey) { |
| 479 | LOG(DEBUG) << "Null key - clearing modifiers."; |
| 480 | return CreateModifierReleaseEvents(); |
| 481 | } |
| 482 | |
| 483 | // Now: The key is either a modifier key or character key. |
| 484 | // Common case - not a modifier key. Need two events - Key press and |
| 485 | // key release. |
| 486 | if (IsModifierKey(key_to_emulate) == false) { |
| 487 | LOG(DEBUG) << "Key: " << key_to_emulate << " is not a modifier."; |
| 488 | |
| 489 | guint translated_key = translate_code_to_gdk_symbol(key_to_emulate); |
| 490 | // First - check to see if this is an lowercase letter or is a |
| 491 | // non-alphanumeric key (which cannot be capitalized) |
| 492 | if ((translated_key != GDK_VoidSymbol) || |
| 493 | (is_lowercase_symbol(key_to_emulate))) { |
| 494 | LOG(DEBUG) << "Lowercase letter or non void gdk symbol."; |
| 495 | // More common case - lowercase letter. |
| 496 | // Create only two events. |
| 497 | // Note that if the Shift modifier is set, this character will |
| 498 | // be converted to uppercase by CreateKeyEvent method. |
| 499 | KeyEventsPair ev = CreateKeyDownUpEvents(key_to_emulate); |
| 500 | ret_list.push_back(ev.first); |
| 501 | ret_list.push_back(ev.second); |
| 502 | } else { |
| 503 | // Uppercase letter/symbol: Fire up shift down event, this key and |
| 504 | // shift up event (unless the Shift modifier is already set) |
| 505 | bool shift_was_set = IsShiftSet(); |
| 506 | LOG(DEBUG) << "Uppercase letter. Was shift set? " << shift_was_set; |
| 507 | if (shift_was_set == false) { |
| 508 | // push shift down event |
| 509 | ret_list.push_front( |
| 510 | CreateGenericModifierKeyEvent(GDK_Shift_L, kKeyPress)); |
| 511 | StoreModifierKeyState(GDK_Shift_L); |
| 512 | } |
| 513 | KeyEventsPair ev = CreateKeyDownUpEvents(key_to_emulate); |
| 514 | // Push the events themselves. |
| 515 | ret_list.push_back(ev.first); |
| 516 | ret_list.push_back(ev.second); |
| 517 | |
| 518 | if (shift_was_set == false) { |
| 519 | // push shift up event |
| 520 | ret_list.push_back( |
| 521 | CreateGenericModifierKeyEvent(GDK_Shift_L, kKeyRelease)); |
| 522 | // Turn OFF the shift modifier! |
| 523 | StoreModifierKeyState(GDK_Shift_L); |
| 524 | } |
| 525 | } |
| 526 | } else { // Modifier key. |
| 527 | // When a modifier key is pressed, the state does not yet change to reflect |
| 528 | // it (on the KeyPress event for the modifier key). When the modifier key is |
| 529 | // released, the state indeed reflects that it was pressed. |
| 530 | LOG(DEBUG) << "Key: " << key_to_emulate << " IS a modifier."; |
no test coverage detected