Download MetaTrader 5

How to disable the backspace key event.

To add comments, please log in or register
Do you want to write a trading robot? Find solution in MQL5 Reference!
ehongyao123
81
ehongyao123 2016.02.29 11:34 

i have create some objects on chart. but if i press the backspace button on keyboard. these objects will be deleted on chart. 

how can i disable this event . thanks . 

ehongyao123
81
ehongyao123 2016.03.01 02:34  
someone help me , thanks .
Hadil Mutaqin SE
2792
Hadil Mutaqin SE 2016.03.01 03:08  
ehongyao123:

i have create some objects on chart. but if i press the backspace button on keyboard. these objects will be deleted on chart. 

how can i disable this event . thanks . 

Set selectable properties to false
Ex Ovo Omnia
3155
Ex Ovo Omnia 2016.03.01 08:18  
Hadil Mutaqin SE:
Set selectable properties to false
Selectable or hidden have no effect on the backspace.
whroeder1
14527
whroeder1 2017.03.24 14:40  
Ex Ovo Omnia: Selectable or hidden have no effect on the backspace.
Back space only deletes selected objects. Unselect them
honest_knave
Moderator
2220
honest_knave 2017.03.24 14:51  
whroeder1:
Back space only deletes selected objects. Unselect them


OK, I'm guilty of resurrecting this thread (and then removing my post as I thought I shouldn't really be resurrecting old threads).

Unfortunately, backspace doesn't care if the object is selected or not. It will always delete the last object created.

As the thread is alive again (sorry!) I'll repost my solution:

The keystroke chartevent fires before the object gets deleted.

So the solution is to create a sacrificial object to be deleted.

This effectively inhibits backspace for the entire chart.

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   if(id==CHARTEVENT_KEYDOWN && lparam==8) ObjectCreate(0,"Nothing",OBJ_LABEL,0,0,0);
  } 
Carl Schreiber
6609
Carl Schreiber 2017.03.24 14:59  
I have a keyboard that allows me to define macro scripts for every button and bind them to a defined program (e.g. ..\terminal). Maybe AutoHotkey provides this too? You have to try!
whroeder1
14527
whroeder1 2017.03.24 15:04  
honest_knave: Unfortunately, backspace doesn't care if the object is selected or not. It will always delete the last object created.
Wrong, it only deletes select objects

honest_knave
Moderator
2220
honest_knave 2017.03.24 15:05  
Carl Schreiber:
I have a keyboard that allows me to define macro scripts for every button and bind them to a defined program (e.g. ..\terminal). Maybe AutoHotkey provides this too? You have to try!


Unfortunately you cannot set backspace as a hotkey in the terminal to fire a script.

So the only solution (that I am aware of) is to have something running on the chart that can detect the backspace keystroke and create the sacrificial object before the delete gets actioned.

honest_knave
Moderator
2220
honest_knave 2017.03.24 15:07  
whroeder1:
Wrong, it only deletes select objects


No,  I'm going with Ovo on this. It will delete objects that are not selected.

Drop this script onto a chart. Then make sure you click in the chart window to get the focus, and press backspace. Goodbye object!

void OnStart()
  {
   string name="my_object";
   ObjectCreate(0,name,OBJ_RECTANGLE_LABEL,0,0,0);
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,100);
   ObjectSetInteger(0,name,OBJPROP_XSIZE,100);
   ObjectSetInteger(0,name,OBJPROP_YSIZE,100);
   ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
  }
honest_knave
Moderator
2220
honest_knave 2017.03.24 15:12  

In addendum to my last, I can't recreate your animated gif.

This is what I believe you are doing:

  1. Create an object
  2. Select the object
  3. Create another object
  4. Press backspace

Your result: the first object (the selected one) is deleted

My result: the second object (the unselected one) is deleted.

Which build are you using?

12
To add comments, please log in or register