Skip to content

Commit 19d617f

Browse files
committed
Updating sending of keystrokes to send keys outside the BMP in IE
1 parent b9b2f22 commit 19d617f

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

cpp/iedriver/InputManager.cpp

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "InputManager.h"
1818

1919
#include <ctime>
20+
#include <codecvt>
21+
#include <locale>
2022

2123
#include "errorcodes.h"
2224
#include "json.h"
@@ -532,8 +534,7 @@ int InputManager::KeyDown(BrowserHandle browser_wrapper,
532534
this->inputs_.push_back(input_element);
533535
} else {
534536
HWND window_handle = browser_wrapper->GetContentWindowHandle();
535-
wchar_t character = key[0];
536-
this->AddKeyboardInput(window_handle, character, false, input_state);
537+
this->AddKeyboardInput(window_handle, key, false, input_state);
537538
}
538539
return status_code;
539540
}
@@ -547,8 +548,7 @@ int InputManager::KeyUp(BrowserHandle browser_wrapper,
547548

548549
if (!this->action_simulator_->UseExtraInfo()) {
549550
HWND window_handle = browser_wrapper->GetContentWindowHandle();
550-
wchar_t character = key[0];
551-
this->AddKeyboardInput(window_handle, character, true, input_state);
551+
this->AddKeyboardInput(window_handle, key, true, input_state);
552552
}
553553
return status_code;
554554
}
@@ -585,19 +585,41 @@ void InputManager::AddMouseInput(HWND window_handle, long input_action, int x, i
585585
}
586586

587587
void InputManager::AddKeyboardInput(HWND window_handle,
588-
wchar_t character,
588+
std::wstring key,
589589
bool key_up,
590590
InputState* input_state) {
591591
LOG(TRACE) << "Entering InputManager::AddKeyboardInput";
592592

593-
std::wstring log_key = this->GetKeyDescription(character);
593+
wchar_t character = key[0];
594+
std::wstring log_key = key;
595+
if (key.size() == 1) {
596+
log_key = this->GetKeyDescription(character);
597+
}
594598
std::string log_event = "key down";
595599
if (key_up) {
596600
log_event = "key up";
597601
}
598602
LOG(DEBUG) << "Queueing SendInput structure for " << log_event
599603
<< " (key: " << LOGWSTRING(log_key) << ")";
600604

605+
if (key.size() > 1) {
606+
// If the key string passed in is greater than a single character,
607+
// we've been sent a Unicode character with surrogate pairs. Do
608+
// no further processing, just create the input items for the
609+
// individual pieces of the surrogate pair, and let the system
610+
// input manager do the rest.
611+
std::wstring::const_iterator it = key.begin();
612+
for (; it != key.end(); ++it) {
613+
KeyInfo surrogate_key_info;
614+
surrogate_key_info.scan_code = static_cast<WORD>(*it);
615+
surrogate_key_info.key_code = 0;
616+
surrogate_key_info.is_extended_key = false;
617+
618+
this->CreateKeyboardInputItem(surrogate_key_info, KEYEVENTF_UNICODE, key_up);
619+
}
620+
return;
621+
}
622+
601623
if (this->IsModifierKey(character)) {
602624
KeyInfo modifier_key_info = { 0, 0, false, false, false, character };
603625
// If the character represents the Shift key, or represents the
@@ -1015,6 +1037,14 @@ KeyInfo InputManager::GetKeyInfo(HWND window_handle, wchar_t character) {
10151037
key_info.key_code = VK_F12;
10161038
key_info.scan_code = VK_F12;
10171039
}
1040+
else if (character == WD_KEY_META) { // Meta
1041+
key_info.key_code = VK_LWIN;
1042+
key_info.scan_code = VK_LWIN;
1043+
}
1044+
else if (character == WD_KEY_R_META) { // Meta
1045+
key_info.key_code = VK_RWIN;
1046+
key_info.scan_code = VK_RWIN;
1047+
}
10181048
else if (character == L'\n') { // line feed
10191049
key_info.key_code = VK_RETURN;
10201050
key_info.scan_code = VK_RETURN;

cpp/iedriver/InputManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class InputManager {
106106
const Json::Value& pause_action);
107107

108108
void AddMouseInput(HWND window_handle, long input_action, int x, int y);
109-
void AddKeyboardInput(HWND window_handle, wchar_t character, bool key_up, InputState* input_state);
109+
void AddKeyboardInput(HWND window_handle, std::wstring key, bool key_up, InputState* input_state);
110110
void AddPauseInput(HWND window_handle, int duration);
111111

112112
void CreateKeyboardInputItem(KeyInfo key_info, DWORD initial_flags, bool is_generating_keyup);

0 commit comments

Comments
 (0)