Skip to content

Choose a key other than Alt to access accelerator key? #10690

Answered by Mbucari
Mbucari asked this question in Q&A
Discussion options

You must be logged in to vote

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 KeyModifiers.Meta.
My only remaining question is, what is the Avalonia.Input.Key for ⌘?

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,
        H…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
2 replies
@Mbucari
Comment options

@maxkatz6
Comment options

Comment options

You must be logged in to vote
6 replies
@Mbucari
Comment options

@Mrxx99
Comment options

@Mbucari
Comment options

@timunie
Comment options

@timunie
Comment options

Answer selected by Mbucari
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants