@@ -641,68 +641,147 @@ void InputManager::AddKeyboardInput(HWND window_handle,
641
641
return ;
642
642
}
643
643
644
+ if (character == WD_KEY_NULL) {
645
+ std::vector<WORD> modifier_key_codes;
646
+ if (input_state->is_shift_pressed ) {
647
+ if (this ->IsKeyPressed (WD_KEY_SHIFT)) {
648
+ modifier_key_codes.push_back (VK_SHIFT);
649
+ this ->UpdatePressedKeys (WD_KEY_SHIFT, false );
650
+ }
651
+ if (this ->IsKeyPressed (WD_KEY_R_SHIFT)) {
652
+ modifier_key_codes.push_back (VK_RSHIFT);
653
+ this ->UpdatePressedKeys (WD_KEY_R_SHIFT, false );
654
+ }
655
+ input_state->is_shift_pressed = false ;
656
+ }
657
+
658
+ if (input_state->is_control_pressed ) {
659
+ if (this ->IsKeyPressed (WD_KEY_CONTROL)) {
660
+ modifier_key_codes.push_back (VK_CONTROL);
661
+ this ->UpdatePressedKeys (WD_KEY_CONTROL, false );
662
+ }
663
+ if (this ->IsKeyPressed (WD_KEY_R_CONTROL)) {
664
+ modifier_key_codes.push_back (VK_RCONTROL);
665
+ this ->UpdatePressedKeys (WD_KEY_R_CONTROL, false );
666
+ }
667
+ input_state->is_control_pressed = false ;
668
+ }
669
+
670
+ if (input_state->is_alt_pressed ) {
671
+ if (this ->IsKeyPressed (WD_KEY_ALT)) {
672
+ modifier_key_codes.push_back (VK_MENU);
673
+ this ->UpdatePressedKeys (WD_KEY_ALT, false );
674
+ }
675
+ if (this ->IsKeyPressed (WD_KEY_R_ALT)) {
676
+ modifier_key_codes.push_back (VK_RMENU);
677
+ this ->UpdatePressedKeys (WD_KEY_R_ALT, false );
678
+ }
679
+ input_state->is_alt_pressed = false ;
680
+ }
681
+
682
+ if (input_state->is_meta_pressed ) {
683
+ if (this ->IsKeyPressed (WD_KEY_META)) {
684
+ modifier_key_codes.push_back (VK_LWIN);
685
+ this ->UpdatePressedKeys (WD_KEY_META, false );
686
+ }
687
+ if (this ->IsKeyPressed (WD_KEY_R_META)) {
688
+ modifier_key_codes.push_back (VK_RWIN);
689
+ this ->UpdatePressedKeys (WD_KEY_R_META, false );
690
+ }
691
+ input_state->is_meta_pressed = false ;
692
+ }
693
+
694
+ std::vector<WORD>::const_iterator it = modifier_key_codes.begin ();
695
+ for (; it != modifier_key_codes.end (); ++it) {
696
+ KeyInfo modifier_key_info = { 0 , 0 , false , false , false , character };
697
+ UINT scan_code = ::MapVirtualKey (*it, MAPVK_VK_TO_VSC);
698
+ modifier_key_info.key_code = *it;
699
+ modifier_key_info.scan_code = scan_code;
700
+ this ->CreateKeyboardInputItem (modifier_key_info,
701
+ KEYEVENTF_SCANCODE,
702
+ true );
703
+ }
704
+ return ;
705
+ }
706
+
644
707
if (this ->IsModifierKey (character)) {
645
708
KeyInfo modifier_key_info = { 0 , 0 , false , false , false , character };
646
709
// If the character represents the Shift key, or represents the
647
710
// "release all modifiers" key and the Shift key is down, send
648
711
// the appropriate down or up keystroke for the Shift key.
649
712
if (character == WD_KEY_SHIFT ||
650
- character == WD_KEY_R_SHIFT ||
651
- (character == WD_KEY_NULL && input_state->is_shift_pressed )) {
713
+ character == WD_KEY_R_SHIFT) {
714
+ WORD key_code = VK_SHIFT;
715
+ if (character == WD_KEY_R_SHIFT) {
716
+ key_code = VK_RSHIFT;
717
+ }
718
+ UINT scan_code = ::MapVirtualKey (key_code, MAPVK_VK_TO_VSC);
652
719
modifier_key_info.key_code = VK_SHIFT;
720
+ modifier_key_info.scan_code = scan_code;
653
721
this ->CreateKeyboardInputItem (modifier_key_info,
654
- 0 ,
722
+ KEYEVENTF_SCANCODE ,
655
723
input_state->is_shift_pressed );
656
724
if (input_state->is_shift_pressed ) {
657
725
input_state->is_shift_pressed = false ;
658
726
} else {
659
727
input_state->is_shift_pressed = true ;
660
728
}
661
- this ->UpdatePressedKeys (WD_KEY_SHIFT , input_state->is_shift_pressed );
729
+ this ->UpdatePressedKeys (character , input_state->is_shift_pressed );
662
730
}
663
731
664
732
// If the character represents the Control key, or represents the
665
733
// "release all modifiers" key and the Control key is down, send
666
734
// the appropriate down or up keystroke for the Control key.
667
735
if (character == WD_KEY_CONTROL ||
668
- character == WD_KEY_R_CONTROL ||
669
- (character == WD_KEY_NULL && input_state->is_control_pressed )) {
736
+ character == WD_KEY_R_CONTROL) {
737
+ WORD key_code = VK_CONTROL;
738
+ if (character == WD_KEY_R_CONTROL) {
739
+ key_code = VK_RCONTROL;
740
+ modifier_key_info.is_extended_key = true ;
741
+ }
742
+ UINT scan_code = ::MapVirtualKey (key_code, MAPVK_VK_TO_VSC);
670
743
modifier_key_info.key_code = VK_CONTROL;
744
+ modifier_key_info.scan_code = scan_code;
671
745
this ->CreateKeyboardInputItem (modifier_key_info,
672
- 0 ,
746
+ KEYEVENTF_SCANCODE ,
673
747
input_state->is_control_pressed );
674
748
if (input_state->is_control_pressed ) {
675
749
input_state->is_control_pressed = false ;
676
750
} else {
677
751
input_state->is_control_pressed = true ;
678
752
}
679
- this ->UpdatePressedKeys (WD_KEY_CONTROL , input_state->is_control_pressed );
753
+ this ->UpdatePressedKeys (character , input_state->is_control_pressed );
680
754
}
681
755
682
756
// If the character represents the Alt key, or represents the
683
757
// "release all modifiers" key and the Alt key is down, send
684
758
// the appropriate down or up keystroke for the Alt key.
685
759
if (character == WD_KEY_ALT ||
686
- character == WD_KEY_R_ALT ||
687
- (character == WD_KEY_NULL && input_state->is_alt_pressed )) {
760
+ character == WD_KEY_R_ALT) {
761
+ WORD key_code = VK_MENU;
762
+ if (character == WD_KEY_R_ALT) {
763
+ key_code = VK_RMENU;
764
+ modifier_key_info.is_extended_key = true ;
765
+ }
766
+ UINT scan_code = ::MapVirtualKey (key_code, MAPVK_VK_TO_VSC);
688
767
modifier_key_info.key_code = VK_MENU;
768
+ modifier_key_info.scan_code = scan_code;
689
769
this ->CreateKeyboardInputItem (modifier_key_info,
690
- 0 ,
770
+ KEYEVENTF_SCANCODE ,
691
771
input_state->is_alt_pressed );
692
772
if (input_state->is_alt_pressed ) {
693
773
input_state->is_alt_pressed = false ;
694
774
} else {
695
775
input_state->is_alt_pressed = true ;
696
776
}
697
- this ->UpdatePressedKeys (WD_KEY_ALT , input_state->is_alt_pressed );
777
+ this ->UpdatePressedKeys (character , input_state->is_alt_pressed );
698
778
}
699
779
700
780
// If the character represents the Meta (Windows) key, or represents
701
781
// the "release all modifiers" key and the Meta key is down, send
702
782
// the appropriate down or up keystroke for the Meta key.
703
783
if (character == WD_KEY_META ||
704
- character == WD_KEY_R_META ||
705
- (character == WD_KEY_NULL && input_state->is_meta_pressed )) {
784
+ character == WD_KEY_R_META) {
706
785
// modifier_key_info.key_code = VK_LWIN;
707
786
// this->CreateKeyboardInputItem(modifier_key_info,
708
787
// 0,
@@ -738,7 +817,6 @@ void InputManager::AddKeyboardInput(HWND window_handle,
738
817
}
739
818
}
740
819
741
-
742
820
unsigned short modifier_key_info = HIBYTE (key_info.key_code );
743
821
if (modifier_key_info != 0 ) {
744
822
// Requested key is a <modifier keys> + <key>. Thus, don't use the key code.
@@ -785,6 +863,12 @@ void InputManager::AddKeyboardInput(HWND window_handle,
785
863
}
786
864
}
787
865
866
+ bool InputManager::IsKeyPressed (wchar_t character) {
867
+ return std::find (this ->pressed_keys_ .begin (),
868
+ this ->pressed_keys_ .end (),
869
+ character) != this ->pressed_keys_ .end ();
870
+ }
871
+
788
872
void InputManager::UpdatePressedKeys (wchar_t character, bool press_key) {
789
873
std::wstring log_string = this ->GetKeyDescription (character);
790
874
if (press_key) {
@@ -1015,6 +1099,7 @@ KeyInfo InputManager::GetKeyInfo(HWND window_handle, wchar_t character) {
1015
1099
else if (character == WD_KEY_SEPARATOR) { // separator
1016
1100
key_info.key_code = VkKeyScanExW (L' ,' , layout);
1017
1101
key_info.scan_code = MapVirtualKeyExW (LOBYTE (key_info.key_code ), 0 , layout);
1102
+ key_info.is_extended_key = true ;
1018
1103
}
1019
1104
else if (character == WD_KEY_SUBTRACT) { // subtract
1020
1105
key_info.key_code = VK_SUBTRACT;
0 commit comments