17
17
#include " InputManager.h"
18
18
19
19
#include < ctime>
20
+ #include < codecvt>
21
+ #include < locale>
20
22
21
23
#include " errorcodes.h"
22
24
#include " json.h"
@@ -532,8 +534,7 @@ int InputManager::KeyDown(BrowserHandle browser_wrapper,
532
534
this ->inputs_ .push_back (input_element);
533
535
} else {
534
536
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);
537
538
}
538
539
return status_code;
539
540
}
@@ -547,8 +548,7 @@ int InputManager::KeyUp(BrowserHandle browser_wrapper,
547
548
548
549
if (!this ->action_simulator_ ->UseExtraInfo ()) {
549
550
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);
552
552
}
553
553
return status_code;
554
554
}
@@ -585,19 +585,41 @@ void InputManager::AddMouseInput(HWND window_handle, long input_action, int x, i
585
585
}
586
586
587
587
void InputManager::AddKeyboardInput (HWND window_handle,
588
- wchar_t character ,
588
+ std::wstring key ,
589
589
bool key_up,
590
590
InputState* input_state) {
591
591
LOG (TRACE) << " Entering InputManager::AddKeyboardInput" ;
592
592
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
+ }
594
598
std::string log_event = " key down" ;
595
599
if (key_up) {
596
600
log_event = " key up" ;
597
601
}
598
602
LOG (DEBUG) << " Queueing SendInput structure for " << log_event
599
603
<< " (key: " << LOGWSTRING (log_key) << " )" ;
600
604
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
+
601
623
if (this ->IsModifierKey (character)) {
602
624
KeyInfo modifier_key_info = { 0 , 0 , false , false , false , character };
603
625
// If the character represents the Shift key, or represents the
@@ -1015,6 +1037,14 @@ KeyInfo InputManager::GetKeyInfo(HWND window_handle, wchar_t character) {
1015
1037
key_info.key_code = VK_F12;
1016
1038
key_info.scan_code = VK_F12;
1017
1039
}
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
+ }
1018
1048
else if (character == L' \n ' ) { // line feed
1019
1049
key_info.key_code = VK_RETURN;
1020
1050
key_info.scan_code = VK_RETURN;
0 commit comments