summaryrefslogtreecommitdiff
path: root/src/gui_w32.c
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2022-06-24 20:18:09 +0100
committerBram Moolenaar <Bram@vim.org>2022-06-24 20:18:09 +0100
commit4e0fc8956649d3208aeaa1642c5efc44e385d77a (patch)
tree20ba9d3693432557ece60be8efd1c1574f460eb2 /src/gui_w32.c
parente9b74c03618e2dcd01cd71f8d62d620fbce884fa (diff)
downloadvim-git-4e0fc8956649d3208aeaa1642c5efc44e385d77a.tar.gz
patch 8.2.5157: MS-Windows GUI: CTRL-key combinations do not always workv8.2.5157
Problem: MS-Windows GUI: CTRL-key combinations do not always work. Solution: Handle special key combinations better. (closes #10613, closes #10602, closes #10579)
Diffstat (limited to 'src/gui_w32.c')
-rw-r--r--src/gui_w32.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/gui_w32.c b/src/gui_w32.c
index 7bdbf418d..ae419053b 100644
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -2055,21 +2055,21 @@ process_message(void)
int i;
UINT scan_code;
- // Construct the state table with only a few modifiers, we don't
- // really care about the presence of Ctrl/Alt as those modifiers are
- // handled by Vim separately.
+ // Construct the keyboard state table, the modifiers can and will
+ // affect the character translation performed by ToUnicode.
+ // Eg. With a Russian keyboard layout pressing 'n' produces 'т' but
+ // Ctrl+p produces 'p', this is essential for the keybindings to
+ // work.
memset(keyboard_state, 0, 256);
+ if (GetKeyState(VK_CONTROL) & 0x8000)
+ keyboard_state[VK_CONTROL] = 0x80;
if (GetKeyState(VK_SHIFT) & 0x8000)
keyboard_state[VK_SHIFT] = 0x80;
if (GetKeyState(VK_CAPITAL) & 0x0001)
keyboard_state[VK_CAPITAL] = 0x01;
- // Alt-Gr is synthesized as Alt + Ctrl.
- if ((GetKeyState(VK_RMENU) & 0x8000)
- && (GetKeyState(VK_CONTROL) & 0x8000))
- {
+ // Alt-Gr is synthesized as (Right)Alt + Ctrl.
+ if ((GetKeyState(VK_RMENU) & 0x8000) && keyboard_state[VK_CONTROL])
keyboard_state[VK_MENU] = 0x80;
- keyboard_state[VK_CONTROL] = 0x80;
- }
// Translate the virtual key according to the current keyboard
// layout.
@@ -2079,6 +2079,16 @@ process_message(void)
// If this is a dead key ToUnicode returns a negative value.
len = ToUnicode(vk, scan_code, keyboard_state, ch, ARRAY_LENGTH(ch),
0);
+ if (len == 0 && keyboard_state[VK_CONTROL])
+ {
+ // Handle one more special case: pressing Ctrl+key may
+ // generate an unprintable ASCII character, try again without
+ // the modifier to get the pressed key value.
+ keyboard_state[VK_CONTROL] = 0;
+ len = ToUnicode(vk, scan_code, keyboard_state, ch,
+ ARRAY_LENGTH(ch), 0);
+ keyboard_state[VK_CONTROL] = 0x80;
+ }
dead_key = len < 0;
if (len <= 0)