Skip to content

Commit

Permalink
Merge pull request #91 from Zorbn/fix-ctrl-number
Browse files Browse the repository at this point in the history
Fix <C-6> (and the rest of <C-[0-9]>)
  • Loading branch information
RMichelsen committed Jul 18, 2023
2 parents b9df10c + 5bf20ad commit 9aa4929
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,24 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
}
}

// Special case for forward slash and semicolon.
// Unfortunately their virtual key codes are not unique and can vary between languages, so this only works for US keyboard layouts.
// See: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
if(!wcscmp(context->locale, L"en-US")) {
bool shift_down = (GetKeyState(VK_SHIFT) & 0x80) != 0;
if(wparam == 0xBF && !shift_down) {
NvimSendSysChar(context->nvim, L'/');
bool shift_down = (GetKeyState(VK_SHIFT) & 0x80) != 0;
if (!shift_down) {
// Allow Nvim to recognize <C-[0-9]>.
// 0x30 is the virtual key code for 0, 0x39 is the virtual key code for 9, and the other numbers are in-between.
if(0x30 <= wparam && wparam <= 0x39) {
NvimSendSysChar(context->nvim, static_cast<wchar_t>(wparam));
}
if(wparam == 0xBA && !shift_down) {
NvimSendSysChar(context->nvim, L';');

// Special case for forward slash and semicolon.
// Unfortunately their virtual key codes are not unique and can vary between languages, so this only works for US keyboard layouts.
// See: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
if(!wcscmp(context->locale, L"en-US")) {
if(wparam == 0xBF) {
NvimSendSysChar(context->nvim, L'/');
}
if(wparam == 0xBA) {
NvimSendSysChar(context->nvim, L';');
}
}
}

Expand Down

0 comments on commit 9aa4929

Please sign in to comment.