Skip to content

Commit 9aa4929

Browse files
authored
Merge pull request #91 from Zorbn/fix-ctrl-number
Fix <C-6> (and the rest of <C-[0-9]>)
2 parents b9df10c + 5bf20ad commit 9aa4929

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

src/main.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,24 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
227227
}
228228
}
229229

230-
// Special case for forward slash and semicolon.
231-
// Unfortunately their virtual key codes are not unique and can vary between languages, so this only works for US keyboard layouts.
232-
// See: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
233-
if(!wcscmp(context->locale, L"en-US")) {
234-
bool shift_down = (GetKeyState(VK_SHIFT) & 0x80) != 0;
235-
if(wparam == 0xBF && !shift_down) {
236-
NvimSendSysChar(context->nvim, L'/');
230+
bool shift_down = (GetKeyState(VK_SHIFT) & 0x80) != 0;
231+
if (!shift_down) {
232+
// Allow Nvim to recognize <C-[0-9]>.
233+
// 0x30 is the virtual key code for 0, 0x39 is the virtual key code for 9, and the other numbers are in-between.
234+
if(0x30 <= wparam && wparam <= 0x39) {
235+
NvimSendSysChar(context->nvim, static_cast<wchar_t>(wparam));
237236
}
238-
if(wparam == 0xBA && !shift_down) {
239-
NvimSendSysChar(context->nvim, L';');
237+
238+
// Special case for forward slash and semicolon.
239+
// Unfortunately their virtual key codes are not unique and can vary between languages, so this only works for US keyboard layouts.
240+
// See: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
241+
if(!wcscmp(context->locale, L"en-US")) {
242+
if(wparam == 0xBF) {
243+
NvimSendSysChar(context->nvim, L'/');
244+
}
245+
if(wparam == 0xBA) {
246+
NvimSendSysChar(context->nvim, L';');
247+
}
240248
}
241249
}
242250

0 commit comments

Comments
 (0)