Skip to content

Commit

Permalink
Pass the scancode in our tunneled DirectKey event (#7298)
Browse files Browse the repository at this point in the history
#7145 introduced a check so that we wouldn't dispatch keys unless they
actually had a scancode. Our synthetic events actually _didn't_ have
scancodes. Not because they couldn't--just because they didn't.

Fixes #7297
  • Loading branch information
DHowett authored Aug 14, 2020
1 parent dcc2799 commit aecd99e
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ namespace winrt::TerminalApp::implementation
// - Implements the Alt handler (per GH#6421)
// Return value:
// - whether the key was handled
bool AppLogic::OnDirectKeyEvent(const uint32_t vkey, const bool down)
bool AppLogic::OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down)
{
if (_root)
{
Expand All @@ -928,7 +928,7 @@ namespace winrt::TerminalApp::implementation
{
if (auto keyListener{ focusedObject.try_as<IDirectKeyListener>() })
{
if (keyListener.OnDirectKeyEvent(vkey, down))
if (keyListener.OnDirectKeyEvent(vkey, scanCode, down))
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace winrt::TerminalApp::implementation

hstring Title();
void TitlebarClicked();
bool OnDirectKeyEvent(const uint32_t vkey, const bool down);
bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down);

void WindowCloseButtonClicked();

Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/IDirectKeyListener.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace TerminalApp
// If you update this one, please update the one in TerminalControl\TermControl.idl
// If you change this interface, please update the guid.
// If you press F7 or Alt and get a runtime error, go make sure both copies are the same.
[uuid("339e1a87-5315-4da6-96f0-565549b6472b")] interface IDirectKeyListener {
Boolean OnDirectKeyEvent(UInt32 vkey, Boolean down);
[uuid("0ddf4edc-3fda-4dee-97ca-a417ee3dd510")] interface IDirectKeyListener {
Boolean OnDirectKeyEvent(UInt32 vkey, UInt8 scanCode, Boolean down);
}
}
8 changes: 3 additions & 5 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,17 +763,15 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// normally. Namely, the keys we're concerned with are F7 down and Alt up.
// Return value:
// - Whether the key was handled.
bool TermControl::OnDirectKeyEvent(const uint32_t vkey, const bool down)
bool TermControl::OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down)
{
const auto modifiers{ _GetPressedModifierKeys() };
auto handled = false;
if (vkey == VK_MENU && !down)
{
// Manually generate an Alt KeyUp event into the key bindings or terminal.
// This is required as part of GH#6421.
// GH#6513 - make sure to set the scancode too, otherwise conpty
// will think this is a NUL
(void)_TrySendKeyEvent(VK_MENU, LOWORD(MapVirtualKeyW(VK_MENU, MAPVK_VK_TO_VSC)), modifiers, false);
(void)_TrySendKeyEvent(VK_MENU, scanCode, modifiers, false);
handled = true;
}
else if (vkey == VK_F7 && down)
Expand All @@ -795,7 +793,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
if (!handled)
{
// _TrySendKeyEvent pretends it didn't handle F7 for some unknown reason.
(void)_TrySendKeyEvent(VK_F7, 0, modifiers, true);
(void)_TrySendKeyEvent(VK_F7, scanCode, modifiers, true);
// GH#6438: Note that we're _not_ sending the key up here - that'll
// get passed through XAML to our KeyUp handler normally.
handled = true;
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation

void CreateSearchBoxControl();

bool OnDirectKeyEvent(const uint32_t vkey, const bool down);
bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down);

bool OnMouseWheel(const Windows::Foundation::Point location, const int32_t delta, const bool leftButtonDown, const bool midButtonDown, const bool rightButtonDown);

Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace Microsoft.Terminal.TerminalControl
// If you update this one, please update TerminalApp\IDirectKeyListener.idl.
// If you change this interface, please update the guid.
// If you press F7 or Alt and get a runtime error, go make sure both copies are the same.
[uuid("339e1a87-5315-4da6-96f0-565549b6472b")] interface IDirectKeyListener {
Boolean OnDirectKeyEvent(UInt32 vkey, Boolean down);
[uuid("0ddf4edc-3fda-4dee-97ca-a417ee3dd510")] interface IDirectKeyListener {
Boolean OnDirectKeyEvent(UInt32 vkey, UInt8 scanCode, Boolean down);
}

runtimeclass CopyToClipboardEventArgs
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ AppHost::~AppHost()
_app = nullptr;
}

bool AppHost::OnDirectKeyEvent(const uint32_t vkey, const bool down)
bool AppHost::OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down)
{
if (_logic)
{
return _logic.OnDirectKeyEvent(vkey, down);
return _logic.OnDirectKeyEvent(vkey, scanCode, down);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AppHost
void AppTitleChanged(const winrt::Windows::Foundation::IInspectable& sender, winrt::hstring newTitle);
void LastTabClosed(const winrt::Windows::Foundation::IInspectable& sender, const winrt::TerminalApp::LastTabClosedEventArgs& args);
void Initialize();
bool OnDirectKeyEvent(const uint32_t vkey, const bool down);
bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down);

private:
bool _useNonClientArea;
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/WindowsTerminal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int __stdcall wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
// been handled we can discard the message before we even translate it.
if (_messageIsF7Keypress(message))
{
if (host.OnDirectKeyEvent(VK_F7, true))
if (host.OnDirectKeyEvent(VK_F7, LOBYTE(HIWORD(message.lParam)), true))
{
// The application consumed the F7. Don't let Xaml get it.
continue;
Expand All @@ -154,7 +154,7 @@ int __stdcall wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
if (_messageIsAltKeyup(message))
{
// Let's pass <Alt> to the application
if (host.OnDirectKeyEvent(VK_MENU, false))
if (host.OnDirectKeyEvent(VK_MENU, LOBYTE(HIWORD(message.lParam)), false))
{
// The application consumed the Alt. Don't let Xaml get it.
continue;
Expand Down

0 comments on commit aecd99e

Please sign in to comment.