Skip to content

Hotkeys

interface cAlgo.API Since 5.4

DesktopCLICloud

Provides access to Hotkeys API for plugins.

Environment behaviour

CLI — not supported. Available to plugins only, and plugins cannot run in the CLI.

Cloud — not supported. Available to plugins only, and plugins cannot run in the cloud.

Definition

public interface Hotkeys

Namespace: cAlgo.API · Group: Hotkeys

Examples

using cAlgo.API;

namespace cAlgo.Plugins;

public partial 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}");
    }
}
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}")
{
  "AccessRights": "None"
}

Methods

Name Description
ClearDesktopCLICloudvoid Clears all added hotkeys.
Remove 2 overloadsDesktopCLICloudbool Removes an hotkey.
TryAdd 2 overloadsDesktopCLICloudbool Adds a new hotkey.