There’s no need for hacks my fren. Here is example EA button which capture left click events.
//+------------------------------------------------------------------+
//| ButtonEA.mq4 |
//| Copyright 2018, Sanjay Balraj |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Sanjay Balraj"
#property version "1.00"
#property strict
#include <ChartObjects\ChartObjectsTxtControls.mqh>
class EAbutton : public CChartObjectButton
{
protected:
bool m_ignore;
bool m_locked_state;
public:
EAbutton()
{
m_ignore = false;
m_locked_state = State();
}
bool Create()
{
if(!CChartObjectButton::Create(0,"EAbutton",0,50,50,500,50))
return false;
Description("Click me!");
return true;
}
void OnChartEvent(int id,long lp,double dp,string sp)
{
if(id==CHARTEVENT_OBJECT_CLICK && sp == Name())
{
State(!State());
m_locked_state = State();
m_ignore = false;
Alert(StringFormat("Button(%s) state = %s",Name(),string(State())));
Description(State() ? "BUTTON_DOWN" : "BUTTON_UP");
}
else
if(id==CHARTEVENT_MOUSE_MOVE && sp == "1" && IsButtonZone((int)lp,(int)dp))
{
if(!m_ignore)
{
m_ignore = true;
State(!State());
}
}
else
if(id==CHARTEVENT_MOUSE_MOVE && !IsButtonZone((int)lp,(int)dp))
{
if(State() != m_locked_state)
{
State(m_locked_state);
m_ignore = false;
}
}
}
protected:
bool IsButtonZone(int x,int y)
{
return (x >= X_Distance() && x <= X_Distance()+X_Size()) && (y >= Y_Distance() && y <= Y_Distance() + Y_Size());
}
};
EAbutton button;
//+------------------------------------------------------------------+
int OnInit()
{
ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
if(!button.Create())
return INIT_FAILED;
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
void OnTick(){}
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
button.OnChartEvent(id,lparam,dparam,sparam);
}
//+------------------------------------------------------------------+