This example code snippet will show you how to add keyboard hotkey events to your chart, we demonstrate using a cTrader indicator, but it can easily be used for a cBot. The idea is that you may wish to execute events when the user presses Alt+A, like executing an order or interacting with the chart.
using cAlgo.API;
using System;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
internal class HotKeys : Indicator
{
[Parameter("Modifier Key", DefaultValue = ModifierKeys.Alt)]
public ModifierKeys ModifierKeyAlt { get; set; }
[Parameter("Key", DefaultValue = Key.A)]
public Key KeyA { get; set; }
public override void Calculate(int index)
{
}
protected override void Initialize()
{
Chart.AddHotkey(() => KeyHandler(), KeyA, ModifierKeyAlt);
}
private void KeyHandler()
{
Chart.DrawStaticText("keys", DateTime.Now.ToString() + "Alt A Key pressed", VerticalAlignment.Top, HorizontalAlignment.Left, Color.Red);
}
}
}
.
The code can also be found on the GitHub repository.
Feel free to comment on the code or post new code snippets.