How can we say to Metatrader5 that we pushed right click ?

 

When we push left click the following code help us to do something(for example comment something):

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
{
   if(id == CHARTEVENT_CLICK)
   {
      Comment("something");      
   }
}

I want to do something when I push right click too. Is it possible?

(At first I must write the following code:

void OnInit()
{
   ChartSetInteger(0,CHART_CONTEXT_MENU, false);
}

)

 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Yes. Thank you.
 
Jo JomaxWhen we push left click the following code help us to do something(for example comment something):

I don't think it is possible, at least not in pure MQL.

It could also be that it is undocumented but possible, however, I don't remember it ever being mentioned in the forum.

 
Fernando Carreiro #:

I don't think it is possible, at least not in pure MQL.

It could also be that it is undocumented but possible, however, I don't remember it ever being mentioned in the forum.

I doubt I understood correctly what exactly you mean, but I suspect it's possible to track right-clicks. Although I've never tried it myself.

I just found something interesting in a AlgoBook that could theoretically help do this:

https://www.mql5.com/en/book/applications/events/events_mouse

In addition, for the CHARTEVENT_MOUSE_MOVE event, the sparam parameter contains a string representation of a bitmask describing the status of mouse buttons and control keys (Ctrl, Shift). Setting a particular bit to 1 means pressing the corresponding button or key.

Bits

Description

0

Left mouse button state

1

Right mouse button state

 
Vladislav Boyko #:

I doubt I understood correctly what exactly you mean, but I suspect it's possible to track right-clicks. Although I've never tried it myself.

I just found something interesting in a AlgoBook that could theoretically help do this:

I think that's exclusive to the mouse move event

try this:

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if(id == CHARTEVENT_MOUSE_MOVE)
   {
      uint state = (uint)sparam;
      
      Print("CHARTEVENT_MOUSE_MOVE triggered: sparam='", sparam, "', state=", state, ", x=", lparam, ", y=", dparam);
      
      if(state == 2) // right mouse click pressed (bit 1)
      {
         Print("Right mouse click held: x=", lparam, ", y=", dparam);
      }
      else
      {
         Print("Mouse moved (no right click): x=", lparam, ", y=", dparam);
      }
   }
}


If you want to stop the context menu interfering with a right click event, you can disable that:

int OnInit()
{
   ChartSetInteger(ChartID(), CHART_CONTEXT_MENU, false);

   return(INIT_SUCCEEDED);
}

but you'll have to close the chart in that case while not being able to remove the indicator as normal (menu disabled on the chart)

 
Conor Mcnamara #:
but you'll have to close the chart in that case while not being able to remove the indicator as normal (menu disabled on the chart)

You can use the "Charts" tab

 
Conor Mcnamara #:

I think that's exclusive to the mouse move event

try this:


If you want to stop the context menu interfering with a right click event, you can disable that:

but you'll have to close the chart in that case while not being able to remove the indicator as normal (menu disabled on the chart)

Yes it's completely true. Thank you very much for the answer.
 
Vladislav Boyko #:

You can use the "Charts" tab

Thank you 
 
Vladislav Boyko #:

You can use the "Charts" tab

 Ah, that's true