-
One of our users recently pointed out that macOS uses Alt key combinations for special characters. Our application makes use of many MenuItem accelerator keys that conflict with their workflow. Is there a way to instead use the Mac cmd key for accelerator keys? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
I am pretty sure hotkeys like "cmd+^" or "⌘+^" would also be allowed. |
Beta Was this translation helpful? Give feedback.
-
I've successfully changed the accelerator key by overriding AccessKeyHandler and modifying the KeyEventArgs as below, then registering my extension with the locator like so: AvaloniaLocator.CurrentMutable.Bind<IAccessKeyHandler>().ToTransient<AccessKeyHandlerEx>(); I've discovered the macOS command KeyModifiers is internal class AccessKeyHandlerEx : AccessKeyHandler
{
protected override void OnPreviewKeyDown(object sender, KeyEventArgs e)
{
if (Configuration.IsWindows && e.Key is Key.LeftCtrl or Key.RightCtrl)
{
var newArgs = new KeyEventArgs
{
Key = Key.LeftAlt,
Handled = e.Handled,
KeyModifiers = e.KeyModifiers,
};
base.OnPreviewKeyDown(sender, newArgs);
e.Handled = newArgs.Handled;
}
}
protected override void OnPreviewKeyUp(object sender, KeyEventArgs e)
{
if (Configuration.IsWindows && e.Key is Key.LeftCtrl or Key.RightCtrl)
{
var newArgs = new KeyEventArgs()
{
Key = Key.LeftAlt,
Handled = e.Handled,
KeyModifiers = e.KeyModifiers,
};
base.OnPreviewKeyUp(sender, newArgs);
e.Handled = newArgs.Handled;
}
}
protected override void OnKeyDown(object sender, KeyEventArgs e)
{
if (Configuration.IsWindows && e.KeyModifiers.HasAllFlags(KeyModifiers.Control))
{
var newArgs = new KeyEventArgs
{
Key = e.Key,
Handled = e.Handled,
KeyModifiers = KeyModifiers.Alt,
};
base.OnKeyDown(sender, newArgs);
e.Handled = newArgs.Handled;
}
}
} |
Beta Was this translation helpful? Give feedback.
I've successfully changed the accelerator key by overriding AccessKeyHandler and modifying the KeyEventArgs as below, then registering my extension with the locator like so:
I've discovered the macOS command KeyModifiers is
KeyModifiers.Meta
.My only remaining question is, what is the
Avalonia.Input.Key
for ⌘?