[KBM] Fix remaps to arrow keys/Home/Ins, etc not working with Windows Terminal (#7143)

* Added MapVirtualKey call to set scancode before calling SendInput

* Updated comment

* Update comment with link

* Added test for dummy key scan code
This commit is contained in:
Arjun Balgovind 2020-10-08 17:52:19 -07:00 committed by GitHub
parent 1390b57d3e
commit c393db0b65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -192,6 +192,10 @@ namespace KeyboardManagerHelper
keyEventArray[index].ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
}
keyEventArray[index].ki.dwExtraInfo = extraInfo;
// Set wScan to the value from MapVirtualKey as some applications may use the scan code for handling input, for instance, Windows Terminal ignores non-character input which has scancode set to 0.
// MapVirtualKey returns 0 if the key code does not correspond to a physical key (such as unassigned/reserved keys). More details at https://github.com/microsoft/PowerToys/pull/7143#issue-498877747
keyEventArray[index].ki.wScan = (WORD)MapVirtualKey(keyCode, MAPVK_VK_TO_VSC);
}
// Function to set the dummy key events used for remapping shortcuts, required to ensure releasing a modifier doesn't trigger another action (For example, Win->Start Menu or Alt->Menu bar)

View File

@ -41,5 +41,19 @@ namespace RemappingLogicTests
Assert::AreEqual(true, bool(input[i].ki.dwFlags & KEYEVENTF_EXTENDEDKEY));
}
}
// Test if SetKeyEvent sets the scan code field to 0 for dummy key
TEST_METHOD (SetKeyEvent_ShouldSetScanCodeFieldTo0_WhenArgumentIsDummyKey)
{
const int nInputs = KeyboardManagerConstants::DUMMY_KEY_EVENT_SIZE;
INPUT input[nInputs] = {};
int index = 0;
KeyboardManagerHelper::SetDummyKeyEvent(input, index, 0);
// Assert that wScan for both inputs is 0
Assert::AreEqual<unsigned int>(0, input[0].ki.wScan);
Assert::AreEqual<unsigned int>(0, input[1].ki.wScan);
}
};
}