Skip to content

Commit 4e0fc89

Browse files
LemonBoybrammool
authored andcommitted
patch 8.2.5157: MS-Windows GUI: CTRL-key combinations do not always work
Problem: MS-Windows GUI: CTRL-key combinations do not always work. Solution: Handle special key combinations better. (closes #10613, closes #10602, closes #10579)
1 parent e9b74c0 commit 4e0fc89

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

src/gui_w32.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ static char *(features[]) =
735735

736736
static int included_patches[] =
737737
{ /* Add new patch number below this line */
738+
/**/
739+
5157,
738740
/**/
739741
5156,
740742
/**/

0 commit comments

Comments
 (0)