@@ -2055,21 +2055,21 @@ process_message(void)
20552055 int i ;
20562056 UINT scan_code ;
20572057
2058- // Construct the state table with only a few modifiers, we don't
2059- // really care about the presence of Ctrl/Alt as those modifiers are
2060- // handled by Vim separately.
2058+ // Construct the keyboard state table, the modifiers can and will
2059+ // affect the character translation performed by ToUnicode.
2060+ // Eg. With a Russian keyboard layout pressing 'n' produces 'т' but
2061+ // Ctrl+p produces 'p', this is essential for the keybindings to
2062+ // work.
20612063 memset (keyboard_state , 0 , 256 );
2064+ if (GetKeyState (VK_CONTROL ) & 0x8000 )
2065+ keyboard_state [VK_CONTROL ] = 0x80 ;
20622066 if (GetKeyState (VK_SHIFT ) & 0x8000 )
20632067 keyboard_state [VK_SHIFT ] = 0x80 ;
20642068 if (GetKeyState (VK_CAPITAL ) & 0x0001 )
20652069 keyboard_state [VK_CAPITAL ] = 0x01 ;
2066- // Alt-Gr is synthesized as Alt + Ctrl.
2067- if ((GetKeyState (VK_RMENU ) & 0x8000 )
2068- && (GetKeyState (VK_CONTROL ) & 0x8000 ))
2069- {
2070+ // Alt-Gr is synthesized as (Right)Alt + Ctrl.
2071+ if ((GetKeyState (VK_RMENU ) & 0x8000 ) && keyboard_state [VK_CONTROL ])
20702072 keyboard_state [VK_MENU ] = 0x80 ;
2071- keyboard_state [VK_CONTROL ] = 0x80 ;
2072- }
20732073
20742074 // Translate the virtual key according to the current keyboard
20752075 // layout.
@@ -2079,6 +2079,16 @@ process_message(void)
20792079 // If this is a dead key ToUnicode returns a negative value.
20802080 len = ToUnicode (vk , scan_code , keyboard_state , ch , ARRAY_LENGTH (ch ),
20812081 0 );
2082+ if (len == 0 && keyboard_state [VK_CONTROL ])
2083+ {
2084+ // Handle one more special case: pressing Ctrl+key may
2085+ // generate an unprintable ASCII character, try again without
2086+ // the modifier to get the pressed key value.
2087+ keyboard_state [VK_CONTROL ] = 0 ;
2088+ len = ToUnicode (vk , scan_code , keyboard_state , ch ,
2089+ ARRAY_LENGTH (ch ), 0 );
2090+ keyboard_state [VK_CONTROL ] = 0x80 ;
2091+ }
20822092 dead_key = len < 0 ;
20832093
20842094 if (len <= 0 )
0 commit comments