CHARTEVENT_CLICK only fires when the mouse click is up.
CHARTEVENT_MOUSE_MOVE can be used to identify click down and up by mouse instead.
To get the keyboard ASCII codes including the CTRL press the wanted key in here .
For instance, pressing CTRL will get 17.
* or just run this and press the desired key to show the key code.
#define TAB_CONTROL_ADDED 17 // control added to tab control bool MouseDown = false, MouseClicked = false; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- set the flag of receiving chart object removal events ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- the key has been pressed if(id==CHARTEVENT_KEYDOWN) { switch(lparam) { case TAB_CONTROL_ADDED: Print("ctrl"); break; default: Print("key ",(int)lparam); break; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ if(id==CHARTEVENT_MOUSE_MOVE) { if(MouseLeftButtonState((uint)sparam) == "DN" && !MouseDown) { MouseDown = true; Print("Mouse down"); } if(MouseLeftButtonState((uint)sparam) == "UP" && MouseDown) { MouseDown = false; Print("Mouse up"); } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ string MouseLeftButtonState(uint state) { string res; res+=(((state& 1)== 1)?"DN":"UP"); // mouse left return(res); }
William Roeder #:
Can I check if CTRL or SHIFT is pressed when using CHARTEVENT_KEYDOWN? - HFT Trading - MQL4 programming forum
Can I check if CTRL or SHIFT is pressed when using CHARTEVENT_KEYDOWN? - HFT Trading - MQL4 programming forum
Marvelous! works like a charm.
Thanks a lot.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
With the above code, I want to achieve: when I ctrl+leftclick, it only shows "ctrl", no "clicked". But in fact, when I press ctrl and hold down left mouse button, it shows "ctrl", then when I release it, it says "clicked", which is weird. I might have understood it wrong, for example, why "id" could be CLICK and MOUSE MOVE at the same time?