| 679 | } |
| 680 | |
| 681 | void InputManager::AddKeyboardInput(HWND window_handle, |
| 682 | std::wstring key, |
| 683 | bool key_up, |
| 684 | InputState* input_state) { |
| 685 | LOG(TRACE) << "Entering InputManager::AddKeyboardInput"; |
| 686 | |
| 687 | wchar_t character = key[0]; |
| 688 | std::wstring log_key = key; |
| 689 | if (key.size() == 1) { |
| 690 | log_key = this->GetKeyDescription(character); |
| 691 | } |
| 692 | std::string log_event = "key down"; |
| 693 | if (key_up) { |
| 694 | log_event = "key up"; |
| 695 | } |
| 696 | LOG(DEBUG) << "Queueing SendInput structure for " << log_event |
| 697 | << " (key: " << LOGWSTRING(log_key) << ")"; |
| 698 | |
| 699 | if (key.size() > 1) { |
| 700 | // If the key string passed in is greater than a single character, |
| 701 | // we've been sent a Unicode character with surrogate pairs. Do |
| 702 | // no further processing, just create the input items for the |
| 703 | // individual pieces of the surrogate pair, and let the system |
| 704 | // input manager do the rest. |
| 705 | std::wstring::const_iterator it = key.begin(); |
| 706 | for (; it != key.end(); ++it) { |
| 707 | KeyInfo surrogate_key_info = { 0, 0, false, false, false, false, L'\0' }; |
| 708 | surrogate_key_info.scan_code = static_cast<WORD>(*it); |
| 709 | surrogate_key_info.key_code = 0; |
| 710 | surrogate_key_info.is_extended_key = false; |
| 711 | |
| 712 | this->CreateKeyboardInputItem(surrogate_key_info, KEYEVENTF_UNICODE, key_up); |
| 713 | } |
| 714 | return; |
| 715 | } |
| 716 | |
| 717 | if (character == WD_KEY_NULL) { |
| 718 | std::vector<WORD> modifier_key_codes; |
| 719 | if (input_state->is_shift_pressed) { |
| 720 | if (this->IsKeyPressed(WD_KEY_SHIFT)) { |
| 721 | modifier_key_codes.push_back(VK_SHIFT); |
| 722 | this->UpdatePressedKeys(WD_KEY_SHIFT, false); |
| 723 | } |
| 724 | if (this->IsKeyPressed(WD_KEY_R_SHIFT)) { |
| 725 | modifier_key_codes.push_back(VK_RSHIFT); |
| 726 | this->UpdatePressedKeys(WD_KEY_R_SHIFT, false); |
| 727 | } |
| 728 | input_state->is_shift_pressed = false; |
| 729 | } |
| 730 | |
| 731 | if (input_state->is_control_pressed) { |
| 732 | if (this->IsKeyPressed(WD_KEY_CONTROL)) { |
| 733 | modifier_key_codes.push_back(VK_CONTROL); |
| 734 | this->UpdatePressedKeys(WD_KEY_CONTROL, false); |
| 735 | } |
| 736 | if (this->IsKeyPressed(WD_KEY_R_CONTROL)) { |
| 737 | modifier_key_codes.push_back(VK_RCONTROL); |
| 738 | this->UpdatePressedKeys(WD_KEY_R_CONTROL, false); |
no test coverage detected