5.2-stable branch (5.3.0 patchlevel 0) on Debian Stretch (qt5).
Hitting "q" when waiting for "pause mouse key" closes the qt terminal, ends the pause and returns MOUSE_KEY 113.
However, if a new plot is made, immediately followed by a new "pause mouse key", the pause ends immediately without further keyboard input, returning MOUSE_KEY -1.
while(1){ pr "plot"; pl sin(x); pr "pause"; pause mouse key; pr sprintf("ended on %d",MOUSE_KEY) }
Output is:
plot
pause
On pressing "q" once:
ended on 113
plot
pause
ended on -1
plot
pause
The second event seems to be returned on terminal initialization - adding a short delay between the plot and "pause mouse key" removes it.
Works as expected in X11 terminal (returns MOUSE_KEY -1)
This is because by default the "q" character closes the plot window (which I strongly dislike). This causes the program to receive two "keyboard events", the "q" itself and the "close".
One fix or work-around is to use the option
set term qt ctrlq
which changes the "close" hot key from "q" to "ctrl-q".
It's not clear to me that there is an obvious expectation whether the "q" will or will not be returned as a separate event from the "close". Also I am not certain whether the ordering of the two events is guaranteed.
If your analysis is correct that the second event is not acted on until the next plot is drawn, I agree that is undesirable. I will see if I can pin that down and make sure that events do not persist across a close+reopen.