A call to MessageBox() make subsequent calls to TerminalInfoInteger(TERMINAL_KEYSTATE_*) return incorrect result?
Doesn't break anything. The message box is functioning; it is looking for a click or key press. When you click and it returns, there is nothing in the keyboard queue to trigger a key Down event.
Doesn't break anything. The message box is functioning; it is looking for a click or key press. When you click and it returns, there is nothing in the keyboard queue to trigger a key Down event.
This is just a suspicion, but have you considered that the Message Box is shifted focus away from the chart window, and that subsequent key events are being directed elsewhere and not the chart?
You may need to have focus brought back to the chart window by having the user select the chart window again.
This is just a suspicion, but have you considered that the Message Box is shifted focus away from the chart window, and that subsequent key events are being directed elsewhere and not the chart?
You may need to have focus brought back to the chart window by having the user select the chart window again.
If it is so, then clicking on the chart doesn't "restore" this focus.
I have recorded a video demonstrating the issue at hand. It goes through the following steps:
- Adding the test EA to the chart.
- Pressing Shift, Ctrl, then both keys. Note the correct return values printed for TerminalInfoInteger().
- Pressing Tab to call MessageBox().
- Closing the message box.
- Pressing Shift, Ctrl again. Note the incorrect return values printed for TerminalInfoInteger().
- Removing the EA.
- Attaching the EA again.
- Pressing Shift and Ctrl keys again - correct values are printed.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
It looks like a call to MessageBox() breaks something in the ability of MetaTrader to detect key presses correctly.
Consider for example this sample EA code:
On a key down event, it will print the key code and will also print the states of the Shift and Ctrl keys. It works correctly, printing either -127 or-128 when Shift or Ctrl are down. On a TAB key press, it will call MessageBox(). After that, no matter what's the real state of Shift and Ctrl keys, TerminalInfoInteger(TERMINAL_KEYSTATE_*) will only return either 0 or 1.
Does anyone know a solution to this?
Re-attaching (or re-compiling) the EA works, but switching timeframe/symbol doesn't.
EDIT: The problem with TerminalInfoInteger(TERMINAL_KEYSTATE_*) persists after you close the message box window. This is not a complaint about not being able to detect Shift/Ctrl presses while a modal window is active.