How to set global keyboard shortcut?

I have a menubar app, I would like to add a global keyboard shortcut, which works even when the menu is closed. I looked at the HotKeyMBS class but I can’t pass an alphabetic character (“w”) as a parameter with KeyCodeForText(“w”), or even with HotKeyMBS.KeyCode(keycode as integer). It works well with special characters (return, Fx, etc.) And then how do I display these shortcuts in my menu (nothing is displayed)? Is this the right approach?

Var keyCodeReturn As Integer = HotKeyMBS.KeyCodeForText("w")
HotKeyReturn = new MyHotKey(keyCodeReturn, HotKeyMBS.CommandKey + HotKeyMBS.ControlKey) //CMD + CTRL + "W"

Thanks all,

Isn’t W already taken by the OS (for Close) ?

Isn’t O already taken by the OS (for Open) ?

No, the keyboard shortcut CMD + CTRL + W is not taken by the system.

I wonder if global shortcuts are actually supported by Xojo? but with MBS it should be possible, right?

Yes. Monkeybread Xojo plugin - HotKeyMBS class

This does not appears in your original post.

… and w for Open…

Your choice.

I did something similar recently.

I started with MBS’s ‘Mouse Click & Keyboard Events’ example.

in the KeyDown event of the AppEvenMonitor in the main window’s controls, I have this code:

If KeyCode = 115 Then //this is the Home key
  If mc.ShiftKey Or mc.AltKey Or mc.CtrlKey Then
    Return//if any of these keys are pressed, exit from routine
  End If
  If mc.CmdKey Then
    AutoCollapse() //executes code for Command + Home key
  End If
End If