Skip to content

KeyTrigger: KeyUp command action is not fired for the modifier keys #77

@pkulikov

Description

@pkulikov

Summary

The following definition does not result into the invocation of a command

<b:KeyTrigger Key="LeftCtrl" FiredOn="KeyUp">
    <b:InvokeCommandAction Command="..." />
</b:KeyTrigger>

(That same behavior is for any modifier key.)

To reproduce

  • Build and run the following WPF app project (.NET Framework 4.7.2): KeyTriggerDemo.zip
  • Press the LEFT CTRL key several times

Expected behavior: Two lines are displayed: "UP UP UP..." and "DOWN DOWN DOWN..."
Observed behavior: No "UP"s are displayed.

Reason

The root cause is in the KeyTrigger.cs file:

private void OnKeyPress(object sender, KeyEventArgs e)
{
if (e.Key == this.Key &&
Keyboard.Modifiers == GetActualModifiers(e.Key, this.Modifiers))
{
this.InvokeActions(e);
}
}

When the CTRL key is UP, the Keyboard.Modifiers is None (at least it has CTRL off), however GetActualModifiers returns the instance with CTRL on. Thus, the if condition returns false and actions are not invoked.

Is that by design or a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions