Skip to content

Possible bug: Inconsistency between WM_KEYDOWN and WM_KEYUP #20002

@logiclrd

Description

@logiclrd

While investigating something related to control key events, I was looking at the source code to TerminalContainer_MessageHook in TerminalContainer.cs and saw this:

case NativeMethods.WindowMessage.WM_SYSKEYDOWN: // fallthrough
case NativeMethods.WindowMessage.WM_KEYDOWN:
{
UnpackKeyMessage(wParam, lParam, out ushort vkey, out ushort scanCode, out ushort flags);
NativeMethods.TerminalSendKeyEvent(this.terminal, vkey, scanCode, flags, true);
break;
}
case NativeMethods.WindowMessage.WM_SYSKEYUP: // fallthrough
case NativeMethods.WindowMessage.WM_KEYUP:
{
// WM_KEYUP lParam layout documentation: https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-keyup
UnpackKeyMessage(wParam, lParam, out ushort vkey, out ushort scanCode, out ushort flags);
NativeMethods.TerminalSendKeyEvent(this.terminal, (ushort)wParam, scanCode, flags, false);
break;
}

This has a "smell" to it: Both handler cases call UnpackKeyMessage populating a local variable vkey, but only one of them actually uses it. The WM_KEYDOWN handler passes vkey on to TerminalSendKeyEvent, but the WM_KEYUP handler passes wParam unaltered for the same parameter.

Is this a bug?

If not, I would recommend calling out the difference between the two TerminalSendKeyEvent calls explicitly, with a comment or a strategically-named local variable or what have you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions