Question about backspace key event for graphical objects

 

Hey everyone!

I'm aware MT4 has the backspace shortcut to delete the last created object. Even though this might be useful in some cases, when creating input fields for graphical panels it presents the issue where deleting a character will also delete an object. I found this comment on the forum: https://www.mql5.com/en/forum/74672#comment_4763143 proposing the creation of a dummy object that can be targeted for deletion when backspace is pressed, allowing the preservation of the main interface.

However, I noticed that when working just with the included CControls class, this situation of the backspace key deleting a part of the panel doesn't happen. I tried diving into the code to see if there's any type of handling for the backspace event to prevent this shortcut to affect the program but I couldn't find anything so far. However, when using some of the graphical interfaces libraries, this does happen.

What I'm trying to find is if the proposed dummy object approach is indeed the best one, or if there's a better way of handling this, as the built-in 'panel' library actually accounts for this somehow.

Any help or guidance is highly appreciated, thanks!

How to disable the backspace key event. - How can I disable backspace on Chart?
How to disable the backspace key event. - How can I disable backspace on Chart?
  • 2016.02.29
  • www.mql5.com
Set selectable properties to false selectable or hidden have no effect on the backspace. ) i'll repost my solution: the keystroke chartevent fires before the object gets deleted. Wrong, it only deletes select objects
 
Fernando Jose Velasco Borea:

Hey everyone!

I'm aware MT4 has the backspace shortcut to delete the last created object. Even though this might be useful in some cases, when creating input fields for graphical panels it presents the issue where deleting a character will also delete an object. I found this comment on the forum: https://www.mql5.com/en/forum/74672#comment_4763143 proposing the creation of a dummy object that can be targeted for deletion when backspace is pressed, allowing the preservation of the main interface.

However, I noticed that when working just with the included CControls class, this situation of the backspace key deleting a part of the panel doesn't happen. I tried diving into the code to see if there's any type of handling for the backspace event to prevent this shortcut to affect the program but I couldn't find anything so far. However, when using some of the graphical interfaces libraries, this does happen.

What I'm trying to find is if the proposed dummy object approach is indeed the best one, or if there's a better way of handling this, as the built-in 'panel' library actually accounts for this somehow.

Any help or guidance is highly appreciated, thanks!

I'm not sure, but I don't think that the [Backspace] affects "hidden" graphical objects.

By "hidden" I mean that they don't appear in the normal "Objects List" panel because of setting the OBJPROP_HIDDEN ...

OBJPROP_HIDDEN

Prohibit showing of the name of a graphical object in the list of objects from the terminal menu "Charts" - "Objects" - "List of objects". The true value allows to hide an object from the list. By default, true is set to the objects that display calendar events, trading history and to the objects created from MQL4 programs. To see such graphical objects and access their properties, click on the "All" button in the "List of objects" window.

bool

ObjectCreate - Object Functions - MQL4 Reference
ObjectCreate - Object Functions - MQL4 Reference
  • docs.mql4.com
ObjectCreate - Object Functions - MQL4 Reference
 
Fernando Carreiro #:

I'm not sure, but I don't think that the [Backspace] affects "hidden" graphical objects.

By "hidden" I mean that they don't appear in the normal "Objects List" panel because of setting the OBJPROP_HIDDEN ...

OBJPROP_HIDDEN

Prohibit showing of the name of a graphical object in the list of objects from the terminal menu "Charts" - "Objects" - "List of objects". The true value allows to hide an object from the list. By default, true is set to the objects that display calendar events, trading history and to the objects created from MQL4 programs. To see such graphical objects and access their properties, click on the "All" button in the "List of objects" window.

bool

Hey Fernando!

Thanks for replying! I was reading about that and unfortunately since the backspace 'event' is a chart shortcut, it seems to affect all objects, as the elements of the panel I'm working with (using the EasyAndFast library) are indeed created as hidden objects, as in, listable only when clicking the "All" button. While reading the forum there are a couple of posts like the one I mentioned, and both suggest the 'dummy' object approach to work around this. 

The thing that got me thinking is the fact that the built in panels library doesn't seem to be affected by this, but while diving into even all the include folder, I couldn't find anything even by searching all files for the CHARTEVENT_KEYDOWN string and/or the lparam==8 which is the ID of the backspace.

I'm fine to implement the dummy object approach, however, if there's a better way, which maybe there is as the built-in code doesn't seem to use this approach, or at least in a way I could find it's implementation, I'd like to implement that better way.

 
Fernando Jose Velasco Borea #:

Hey Fernando!

Thanks for replying! I was reading about that and unfortunately since the backspace 'event' is a chart shortcut, it seems to affect all objects, as the elements of the panel I'm working with (using the EasyAndFast library) are indeed created as hidden objects, as in, listable only when clocking the "All" button. While reading the forum there are a couple of posts like the one I mentioned, and both suggest the 'dummy' object approach to work around this. 

The thing that got me thinking is the fact that the built in panels library doesn't seem to be affected by this, but while diving into even all the include folder, I couldn't find anything even by searching all files for the CHARTEVENT_KEYDOWN string and/or the lparam==8 which is the ID of the backspace.

I'm fine to implement the dummy object approach, however, if there's a better way, which maybe there is as the built-in code doesn't seem to use this approach, or at least in a way I could find it's implementation, I'd like to implement that better way.

Run it through the debugger and see what its doing. That may give you a clue.

 
Fernando Carreiro #:

Run it through the debugger and see what its doing. That may give you a clue.

I just finished checking it out on the debugger (a panel using the built in classes) and I wasn't able to spot any special handling when the backspace is pressed.

Everything through the library seems to return false as the backspace is not "tied" to an event handler, and it crossed my mind returning false from the OnChartEvent to see if maybe that's the better approach but recalled that the return type of it is void.

The only curious thing I found is that pressing backspace also triggers two more events related to the MinMax handling, but still, while going through the debugger, I wasn't able to spot any special treatment, or even check for the backspace key.


Reason: