question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyModifiers in button click event

See original GitHub issue

Is your feature request related to a problem? Please describe. It is a common use case to identify any modifier key is pressed when a button is clicked, either with pointer or keyboard. In button definition, both PointerEventArgs and KeyEventArgs carries KeyModifiers, but when forwarding to OnClick method, this information is lost. It would be helpful to pass this information to OnClick method, otherwise I have to override all key/pointer methods when inheriting from Button.

Describe the solution you’d like

class ClickEventArgs:RoutedEventArgs
{
    public KeyModifiers KeyModifiers { get; }
}
internal interface IClickableControl
{
    event EventHandler<ClickEventArgs> Click;
}

Describe alternatives you’ve considered

Additional context my actual use case:

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
    base.OnApplyTemplate(e);
    var button = e.NameScope.Find<RepeatButton>("PART_Button");
    button.Click += OnButtonClick;
}

private void OnButtonClick(object? sender, RoutedEventArgs args)
{
    // When Shift is pressed, use logic 1, else use logic 2.
}
``

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
maxkatz6commented, May 9, 2023

@rabbitism as discussed, we think it’s a good idea to have RoutedEventArgs.Inner.

  1. It needs clear remark that it’s not guaranteed to be of any specific value at any time.
  2. ClickEventArgs, ContextMenuRequested, PointerEntered/PointerExited can be first to implement support. I guess some controls might also benefit from it (expander, spinner?).
  3. We are not sure if this property should be mutable or init-only. If it can be init-only, that’s probably better for the beginning.
0reactions
rabbitismcommented, May 9, 2023

@maxkatz6 i will think about it. Inner need to be immutable, or there will be infinite loop when getting most inner exception.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Event Handling | Vue.js
Inline handlers: Inline JavaScript to be executed when the event is triggered (similar to the native onclick attribute). Method handlers: A property name...
Read more >
Triggering click event with modifier keys on input element
I'm writing a test for some functionality that involves user shift-clicking on a checkbox. I'm using $('input').trigger($.Event('click', { ...
Read more >
KeyboardEvent: getModifierState() method - Web APIs | MDN
The KeyboardEvent.getModifierState() method returns the current state of the specified modifier key: true if the modifier is active (that is ...
Read more >
Vue Event Modifiers
The event modifier .once can be used after both keyboard and mouse click events. Keyboard Key Event Modifiers. We have three different keyboard...
Read more >
Check which modifier key is pressed - Windows Forms .NET
When a modifier key is pressed in combination with other keys or even a mouse click, your application can respond appropriately. For example...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found