Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Alt-Numpad handling #17637

Merged
merged 2 commits into from
Aug 7, 2024
Merged

Implement Alt-Numpad handling #17637

merged 2 commits into from
Aug 7, 2024

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Jul 31, 2024

This adds an indirection for _KeyHandler so that OnDirectKeyEvent
can call _KeyHandler. This allows us to consistently handle
Alt-key-up events. Then I added custom handling for Alt+ddd (OEM),
Alt+0ddd (ANSI), and Alt+'+'+xxxx (Unicode) sequences, due to the
absence of Alt-key events with xaml islands and our TSF control.

Closes #17327

Validation Steps Performed

This comment has been minimized.

Comment on lines -1466 to -1509
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.
(void)_TrySendKeyEvent(VK_MENU, scanCode, modifiers, false);
handled = true;
}
else if ((vkey == VK_F7 || vkey == VK_SPACE) && down)
{
// Manually generate an F7 event into the key bindings or terminal.
// This is required as part of GH#638.
// Or do so for alt+space; only send to terminal when explicitly unbound
// That is part of #GH7125
auto bindings{ _core.Settings().KeyBindings() };
auto isUnbound = false;
const KeyChord kc = {
modifiers.IsCtrlPressed(),
modifiers.IsAltPressed(),
modifiers.IsShiftPressed(),
modifiers.IsWinPressed(),
gsl::narrow_cast<WORD>(vkey),
0
};

if (bindings)
{
handled = bindings.TryKeyChord(kc);

if (!handled)
{
isUnbound = bindings.IsKeyChordExplicitlyUnbound(kc);
}
}

const auto sendToTerminal = vkey == VK_F7 || (vkey == VK_SPACE && isUnbound);

if (!handled && sendToTerminal)
{
// _TrySendKeyEvent pretends it didn't handle F7 for some unknown reason.
(void)_TrySendKeyEvent(gsl::narrow_cast<WORD>(vkey), 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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming these just got subsumed into the key handler, and none of this special logic to ensure the following keys work is needed?

  • release alt -> send key to app (win32IM)
  • F7/Space pressed -> activate key bindings, or send to terminal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a glance it looked like all of that code is covered by our generic key handling already.

Alt key up? That's a fall-through to _TrySendKeyEvent anyway already. ✅
Alt+Space? We do a keybinding lookup, it fails, it falls through to _TrySendKeyEvent. ✅
F7? We do a keybinding lookup, it fails, it falls through to _TrySendKeyEvent. ✅

Seems good to me. In my testing it was.

codepage = ansi ? 1252 : 437;
}

// The OS code seemed to also simply cut off the last byte in the accumulator.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raymond Chen documented this!

Copy link
Member Author

@lhecker lhecker Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was 🤏 this close to just scrapping the entire weird ACP/OEM support. It's not supported in any application that uses CP_UTF8 as its ACP anyway, so I'm not sure if there's any point for us to support it either.

@lhecker
Copy link
Member Author

lhecker commented Aug 7, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lhecker lhecker merged commit 2fab986 into main Aug 7, 2024
20 checks passed
@lhecker lhecker deleted the dev/lhecker/17327-alt-numpad branch August 7, 2024 07:32
@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Priority-3 A description (P3) Product-Terminal The new Windows Terminal. labels Aug 7, 2024
DHowett pushed a commit that referenced this pull request Aug 23, 2024
This adds an indirection for `_KeyHandler` so that `OnDirectKeyEvent`
can call `_KeyHandler`. This allows us to consistently handle
Alt-key-up events. Then I added custom handling for Alt+ddd (OEM),
Alt+0ddd (ANSI), and Alt+'+'+xxxx (Unicode) sequences, due to the
absence of Alt-key events with xaml islands and our TSF control.

Closes #17327

## Validation Steps Performed
* Tested it according to https://conemu.github.io/en/AltNumpad.html
* Unbind Alt+Space
* Run `showkey -a`
* Alt+Space generates `^[ `
* F7 generates `^[[18~`

(cherry picked from commit 2fab986)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmszgSCpCg
Service-Version: 1.21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-3 A description (P3) Product-Terminal The new Windows Terminal.
Projects
Development

Successfully merging this pull request may close these issues.

Alt + numpad combination does not work anymore
3 participants