ChartMouseEventArgs release Alt key not work as it suppose?

ChartMouseEventArgs release Alt key not work as it suppose?
14 May 2022, 23:44
Hello,
I have the below code, which is supposed to display Mouse X, Y values when I was moving the mouse with Alt pressed in the chart area. And release Alt, moving the mouse should make the message disappear.
The message appearing with Alt pressed has no problem. However, when I release the Alt key, the message does not always disappear, esp. when I stopped moving the mouse and then release the Alt key, even if the mouse moves again, the message stays still. Can you explain and help optimise the coding?
BTW, when I activate another window e.g. visual studio and move the mouse back to the chart with this indicator, releasing Alt did make the message disappear every time. But, by clicking the chart to activate cTrader window, the problem back again. It is strange, isn't it?
Thanks.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewIndicator : Indicator
{
private ChartStaticText tx_Rsch;
protected override void Initialize()
{
tx_Rsch = Chart.DrawStaticText("Debugging", "Start Debugging..", VerticalAlignment.Bottom, HorizontalAlignment.Center, Color.FromHex("AAEEDDCC"));
Chart.MouseMove += Chart_MouseMove;
}
public override void Calculate(int index)
{
}
private void Chart_MouseMove(ChartMouseEventArgs obj)
{
if ( obj.AltKey ) { tx_Rsch.Text = string.Format("X: {0} Y: {1}", obj.MouseX, obj.MouseY); }
else if ( !obj.AltKey ) { tx_Rsch.Text = ""; }
}
}
}
Replies
Capt.Z-Fort.Builder
16 May 2022, 22:47
RE:
Thanks, I decide to use Chart.MouseDown to clear the message. :)
amusleh said:
Hi,
Try Ctrl button instead of Alt:
using cAlgo.API; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewIndicator : Indicator { private ChartStaticText tx_Rsch; protected override void Initialize() { tx_Rsch = Chart.DrawStaticText("Debugging", "Start Debugging..", VerticalAlignment.Bottom, HorizontalAlignment.Center, Color.FromHex("AAEEDDCC")); Chart.MouseMove += Chart_MouseMove; Chart.MouseLeave += Chart_MouseLeave; } public override void Calculate(int index) { } private void Chart_MouseMove(ChartMouseEventArgs obj) { tx_Rsch.Text = obj.CtrlKey ? string.Format("X: {0} Y: {1}", obj.MouseX, obj.MouseY) : string.Empty; } private void Chart_MouseLeave(ChartMouseEventArgs obj) { tx_Rsch.Text = string.Empty; } } }
Alt pauses the indicator event loop until you click somewhere or press another keyboard key.
@Capt.Z-Fort.Builder
amusleh
16 May 2022, 10:20
Hi,
Try Ctrl button instead of Alt:
Alt pauses the indicator event loop until you click somewhere or press another keyboard key.
@amusleh