how is possible use mouse + shift in mql4 ?

 

Hi i try to use in my EA  the  combo shift + mouse left  click    i build  a EA in this mode (i write only a part because is so long a script  but if  someone  want  all i can past )

    if (id == CHARTEVENT_CLICK)
    {
        //--- Prepare variables
        int      x     = (int)lparam;
        int      y     = (int)dparam;
        datetime dt    = 0;
        double   price = 0;
        int      window = 0;
        
        //--- Check if the Shift key is pressed
        if ((state& 4)== 4)  //  corrispond at button Shift
        {

but when i try to use mouse  left butto + shift  not work, but if i remove  the 

if ((state& 4)== 4)  /

it work but ofcourse without shift use, anyone  can help me ?

 
faustf:

Hi i try to use in my EA  the  combo shift + mouse left  click    i build  a EA in this mode (i write only a part because is so long a script  but if  someone  want  all i can past )

but when i try to use mouse  left butto + shift  not work, but if i remove  the 

it work but ofcourse without shift use, anyone  can help me ?

I would say, CHART_EVENT_CLICK is not triggered with a key press, you need to track both events separately.

First comes event keypress, then a second call happens with mouse click...

So you need to record the shift button state in key press event, and when the mouse click event arrives, check your recording about shift key as well...
 
Dominik Christian Egert #:
I would say, CHART_EVENT_CLICK is not triggered with a key press, you need to track both events separately.

First comes event keypress, then a second call happens with mouse click...

So you need to record the shift button state in key press event, and when the mouse click event arrives, check your recording about shift key as well...
do you have some example for do that ?
 
faustf #:
do you have some example for do that ?
I don't, but maybe someone else...
 

Try this example :

As Dominik said the click among the key presses is too late to catch the shift so you can use a timer to kill the "indication" the shift is held down.

#property copyright "discussion"
#property link      "https://www.mql5.com/en/forum/450069"
#property version   "1.00"
#property strict

bool isShiftDown=false;
uint shiftHoldTimeStart=0;
long cancelAfterMS=333;
int OnInit()
  {
   isShiftDown=false;
   shiftHoldTimeStart=0;
   while(!EventSetMillisecondTimer(44)){
        Print("Setting timer , please wait...");
        Sleep(44);
        }
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
  }

void OnTick()
  {
  }
void OnTimer()
  {
  uint now=GetTickCount();
  long difference=now-shiftHoldTimeStart;
  if(now<shiftHoldTimeStart){difference=UINT_MAX+now-shiftHoldTimeStart;}
  if(difference>cancelAfterMS){
    isShiftDown=false;
    }
  }
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
  if(id==CHARTEVENT_KEYDOWN){
    //Print("L("+IntegerToString(lparam)+")D("+DoubleToString(dparam,0)+")S("+sparam+")");
    //holding shift down prints this L(16)D(1)S(16426)
      if(lparam==16&&dparam==1.0&&sparam=="16426")
        {
        isShiftDown=true;
        //we log the ticker time shift was pressed continuously
        shiftHoldTimeStart=GetTickCount();
        }else{
        isShiftDown=false;
        }
    }
  //if shift is down
  if(id==CHARTEVENT_CLICK){
    if(isShiftDown){Alert("pop");isShiftDown=false;}
    }  
  }
 
Lorentzos Roussos #:

Try this example :

As Dominik said the click among the key presses is too late to catch the shift so you can use a timer to kill the "indication" the shift is held down.

thanks so much i study
 

how  remove  the object  in chart ??  i used  this  code in onDeint  but not  work

 //--- delete all objects 
   int obj_total=ObjectsTotal(); 
   PrintFormat("Total %d objects",obj_total); 
   for(i=obj_total-1;i>=0;i--) 
     { 
      string name=ObjectName(i); 
      PrintFormat("object %d: %s",i,name); 
      ObjectDelete(name); 
     } 
 
faustf #:

how  remove  the object  in chart ??  i used  this  code in onDeint  but not  work

You can have a "tag" of the objects of the indicator/ea 

string system_tag="EA_";

This prefix is used in all the object this ea/indicator creates

And on deinit you call :

ObjectsDeleteAll(ChartID(),system_tag);
 
 sorry i dont understund  where  i msut  use
string system_tag="EA_";
//+------------------------------------------------------------------+
//|                                                  BUTTONCLICK.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#include <Gui.mqh>

extern color    BackgColore="clrGray";
extern color    TextColore="clrWhite";
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
      Create_Button(0,                    // chart's ID
                    "Button_Apri",         // button name
                    0,                    // X coordinate
                    90,                   // Y coordinate
                    60,                   // button width
                    20,                   // button height
                    CORNER_LEFT_UPPER,    // chart corner for anchoring
                    "APRI",                // text
                    "Courier New",        // font
                    10,                   // font size
                    TextColore,             // text color
                    BackgColore,              // background color
                    false                 // in the background
                      );
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   ObjectsDeleteAll(ChartID(),system_tag);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
 
faustf #:
 sorry i dont understund  where  i msut  use
//+------------------------------------------------------------------+
//|                                                  BUTTONCLICK.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#include <Gui.mqh>

extern color    BackgColore="clrGray";
extern color    TextColore="clrWhite";
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
string system_tag="EA_";
int OnInit()
  {
//---
      Create_Button(0,                    // chart's ID
                    system_tag+"Button_Apri",         // button name
                    0,                    // X coordinate
                    90,                   // Y coordinate
                    60,                   // button width
                    20,                   // button height
                    CORNER_LEFT_UPPER,    // chart corner for anchoring
                    "APRI",                // text
                    "Courier New",        // font
                    10,                   // font size
                    TextColore,             // text color
                    BackgColore,              // background color
                    false                 // in the background
                      );
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   ObjectsDeleteAll(ChartID(),system_tag);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
Reason: