Do you know that you can click and drag the date/time axis. Right to zoom in, left to zoom out.
OnChartEvent() function with CHARTEVENT_KEYDOWN is to survey the keyboard.
Nikolay:
Keycodes: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000520.html
I found it:
#import "user32.dll"
void keybd_event(int bVk,int bScan,int dwFlags,int dwExtraInfo);
keybd_event(187,0,0,0); //+ button
keybd_event(189,0,0,0); //- button
I am trying to make a custom indicator and want some thing like.
if(CTRL + Q) {
Alert("Hello World")
}
how would you code this?
The return value of the keybd_event is void so not sure how to do.
![mql4 pressing two keyboard buttons at the same time mql4 pressing two keyboard buttons at the same time](/i/community/logo_mql5_small.png)
mql4 pressing two keyboard buttons at the same time
- www.mql5.com
Hi all I want to make a custom indicator which detects the pressing down of multiple keys...
Ok so I worked out what that those lines of code do.
keybd_event(187,0,0,0); //+ button
means press + button. But how does mql4 detect multiple key presses? CHARTEVENT_KEYDOWN only takes one sparam argument.
traderbigbear92: But how does mql4 detect multiple key presses? CHARTEVENT_KEYDOWN only takes one sparam argument.
| It doesn't like every other Windows program. Key (e.g. Alt) down - remember, key down - process key modified by (e.g. Alt.) |
Nikolay:
I found it:
#import "user32.dll"
void keybd_event(int bVk,int bScan,int dwFlags,int dwExtraInfo);
keybd_event(187,0,0,0); // NOT + button, but =+ button keybd_event(189,0,0,0); // NOT - button, but -_ button //---- keybd_event(107,0,0,0); // 107 the + code numbers keyboard keybd_event(109,0,0,0); // 109 the - code numbers keyboard //-- for Q and R keybd_event(81,0,0,0); // 81 the Q code numbers keyboard keybd_event(82,0,0,0); // 82 the R code numbers keyboard //--- // I use this code on my indicator like code below // and working smoothly, no problems. #include <WinUser32.mqh> #define KEY_PLUS 107 #define KEY_MINUS 109 void OnChartEvent(const int id, // Event identifier const long &lparam, // Event parameter of long type const double &dparam, // Event parameter of double type const string &sparam) // Event parameter of string type { //--- ResetLastError(); RefreshRates(); //-- static bool keyPressed=false; //--- this is an Event of a keystroke if(id==CHARTEVENT_KEYDOWN) { if(lparam==KEY_PLUS || lparam==KEY_MINUS) { if(!keyPressed) keyPressed=true; else keyPressed=false; } //-- switch(int(lparam)) { case KEY_PLUS: { .... etc } break; case KEY_MINUS: { .... etc } break; } } } //--------------------------------------------//
static datetime lastctrl=0; void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam) { if(id==CHARTEVENT_KEYDOWN) { Print("lparam:"+lparam+" dparam:"+dparam+" sparam:"+sparam); if(lparam==17) lastctrl=TimeCurrent(); if(TimeCurrent()-lastctrl<2) { if (lparam == 49) OpenBuy(); if (lparam == 51) OpenSell(); if (lparam == 48) CloseAll(); } } }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
How can I program triggering a key press/event?
For the following use case: Normally one can zoom with the "+" and "-" keys, but I would like to zoom with "q" and "r" and my idea is when "q" is pressed to trigger pressing the "+" key. Or are there better ideas how to create this use case?