Skip to content

KeyboardShortcuts class

The IDE's keyboard-shortcut registry --- reached through Host.KeyboardShortcuts. Call Add to bind a key combination to a callback. There is no removal API; the registration is released when the addin is unloaded.

vb
Private Sub Host_OnProjectLoaded()
    Host.KeyboardShortcuts.Add "{CTRL}{SHIFT}d", AddressOf ToggleDebugMode
End Sub

Private Sub ToggleDebugMode()
    debugMode = Not debugMode
    Host.DebugConsole.PrintText "Debug mode " & If(debugMode, "ON", "OFF")
End Sub

The shortcut is global to the IDE and fires regardless of which pane has focus, as long as the IDE itself has the OS-level focus. The callback runs on the IDE's UI thread.

Methods

Add

Registers a new keyboard shortcut.

Syntax: keyboardShortcuts.Add keyString, Callback

keyString

required The key combination, as a String. The literal key character is preceded by zero or more modifier prefixes from the set {CTRL}, {SHIFT}, {ALT}. The prefixes are case-insensitive; the trailing key character matches the same key the user would press.

ExampleCombination
"{CTRL}d"Ctrl + D
"{CTRL}{SHIFT}d"Ctrl + Shift + D
"{ALT}f"Alt + F
"f1"F1 (no modifier)
Callback

required The callback. Pass AddressOf a sub of signature Sub() (no arguments). LongPtr.

The callback runs on the IDE's UI thread. Long-running work inside the callback will block the IDE until it returns --- keep the callback short and offload heavy work to a background mechanism when needed.

twinBASIC and LOGO copyright of "WaynePhillipsEA" author