Skip to content

Hotkeys

Summary

Provides access to Hotkeys API for plugins.

Signature

1
public abstract interface Hotkeys

Namespace

cAlgo.API

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 using cAlgo.API;
 namespace cAlgo.Plugins;
 [Plugin(AccessRights = AccessRights.None)]
 public class HotkeysTest : Plugin
 {
     protected override void OnStart()
     {
         var panel = new StackPanel { Orientation = Orientation.Vertical };
         var addHotkeyWithModifierButton = new Button { Text = "Add Hotkey R+Alt" };
         addHotkeyWithModifierButton.Click += args =>
         {
             Print($"Hotkey add result: {Hotkeys.TryAdd(Key.R, ModifierKeys.Alt, HotkeyHandler)}");
         };
         var removeHotkeyWithModifierButton = new Button { Text = "Remove Hotkey R+Alt" };
         removeHotkeyWithModifierButton.Click += args =>
         {
             Print($"Hotkey remove result: {Hotkeys.Remove(Key.R, ModifierKeys.Alt)}");
         };
         var addHotkeyWithoutModifierButton = new Button { Text = "Add Hotkey Q" };
         addHotkeyWithoutModifierButton.Click += args =>
         {
             Print($"Hotkey add result: {Hotkeys.TryAdd(Key.Q, HotkeyHandler)}");
         };
         var removeHotkeyWithoutModifierButton = new Button { Text = "Remove Hotkey Q" };
         removeHotkeyWithoutModifierButton.Click += args =>
         {
             Print($"Hotkey add result: {Hotkeys.Remove(Key.Q)}");
         };
         var cleanButton = new Button { Text = "Clear Hotkeys" };
         cleanButton.Click += args =>
         {
             Hotkeys.Clear();
         };
         panel.AddChild(addHotkeyWithModifierButton);
         panel.AddChild(removeHotkeyWithModifierButton);
         panel.AddChild(addHotkeyWithoutModifierButton);
         panel.AddChild(removeHotkeyWithoutModifierButton);
         panel.AddChild(cleanButton);
         var block = Asp.SymbolTab.AddBlock("Hotkeys");
         block.Child = panel;
     }
     private void HotkeyHandler(HotkeyArgs args)
     {
         Print($"Hotkey triggered: {args.Key} + {args.Modifiers}");
     }
 }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 import clr
 clr.AddReference("cAlgo.API")
 from cAlgo.API import *
 from System import Action
 class Test():
     def on_start(self):
         panel = StackPanel()
         panel.Orientation = Orientation.Vertical
         addHotkeyWithModifierButton = Button()
         addHotkeyWithModifierButton.Text = "Add Hotkey R+Alt"
         addHotkeyWithModifierButton.Click += lambda args: print(f"Hotkey add result: {api.Hotkeys.TryAdd(Key.R, ModifierKeys.Alt, Action[HotkeyArgs](self.hotkey_handler))}")
         removeHotkeyWithModifierButton = Button()
         removeHotkeyWithModifierButton.Text = "Remove Hotkey R+Alt"
         removeHotkeyWithModifierButton.Click += lambda args: print(f"Hotkey remove result: {api.Hotkeys.Remove(Key.R, ModifierKeys.Alt)}")
         addHotkeyWithoutModifierButton = Button()
         addHotkeyWithoutModifierButton.Text = "Add Hotkey Q"
         addHotkeyWithoutModifierButton.Click += lambda args: print(f"Hotkey add result: {api.Hotkeys.TryAdd(Key.Q, Action[HotkeyArgs](self.hotkey_handler))}")
         removeHotkeyWithoutModifierButton = Button()
         removeHotkeyWithoutModifierButton.Text = "Remove Hotkey Q"
         removeHotkeyWithoutModifierButton.Click += lambda args: print(f"Hotkey add result: {api.Hotkeys.Remove(Key.Q)}")
         cleanButton = Button()
         cleanButton.Text = "Clear Hotkeys"
         cleanButton.Click += lambda args: api.Hotkeys.Clear()
         panel.AddChild(addHotkeyWithModifierButton)
         panel.AddChild(removeHotkeyWithModifierButton)
         panel.AddChild(addHotkeyWithoutModifierButton)
         panel.AddChild(removeHotkeyWithoutModifierButton)
         panel.AddChild(cleanButton)
         block = api.Asp.SymbolTab.AddBlock("Hotkeys")
         block.Child = panel
     def hotkey_handler(self, args):
         print(f"Hotkey triggered: {args.Key} + {args.Modifiers}")

Methods

TryAdd (2)

TryAdd (1 of 2)

Summary

Adds a new hotkey.

Signature

1
public abstract bool TryAdd(Key key, Action<HotkeyArgs> handler)

Parameters

Name Type Description
key Key Main Key
handler Action Handler action

Return Value

bool

TryAdd (2 of 2)

Summary

Adds a new hotkey.

Signature

1
public abstract bool TryAdd(Key key, ModifierKeys modifiers, Action<HotkeyArgs> handler)

Parameters

Name Type Description
key Key Main Key
modifiers ModifierKeys The modifier key
handler Action Handler action

Return Value

bool

Remove (2)

Remove (1 of 2)

Summary

Removes an hotkey.

Signature

1
public abstract bool Remove(Key key)

Parameters

Name Type Description
key Key Main Key

Return Value

bool

Remove (2 of 2)

Summary

Removes an hotkey.

Signature

1
public abstract bool Remove(Key key, ModifierKeys modifiers)

Parameters

Name Type Description
key Key Main Key
modifiers ModifierKeys The modifier key

Return Value

bool

Clear

Summary

Clears all added hotkeys.

Signature

1
public abstract void Clear()

Return Value

void