Shift- (or Ctrl-, or ... ) Clicks and commands #17874
Replies: 3 comments 2 replies
-
I'd suggest you just listen for PointerPressed event. The event args should provide the needed modifiers. Call the command from the ViewModel then (DataContext is your VM) |
Beta Was this translation helpful? Give feedback.
-
It is WPF's static (only the OS knows the key state reliably -- if you start pressing CONTROL with focus in another app, and then click a button in your app, your solution will not know the Control state because it never got the KeyEvent, right?) |
Beta Was this translation helpful? Give feedback.
-
You can use attached behaviors
|
Beta Was this translation helpful? Give feedback.
-
Hi,
I could not find a simple and easy way to handle shilft-ed or control-led clicks on command using Avalonia API's so I created this class:
`
public sealed class Keyboard
{
private Window? window;
}
`
I create a single instance of it with the MSFT IoC/Di system,start it and then use it anywhere this way:
`
var keyboard = App.GetRequiredService();
bool isShifted = keyboard.Modifiers.HasFlag(KeyModifiers.Shift);
`
Now the questions...
Is there a better and simple way to achieve the same functionality ?
Have I missed something ?
Thoughts, comments ?
Thanks and Happy New Year.
L.
Beta Was this translation helpful? Give feedback.
All reactions