I'm trying to provide basic keyboard interaction for my gnuplot script.
With gnuplot 5.4 patchlevel 1
I'm using MOUSE_CHAR as documented, I believe, however with the simplest script below, I get an error no matter what key I press.
while (1) {
pause mouse keypress
show variable MOUSE_
if (exists("MOUSE_CHAR")) {
if (MOUSE_CHAR == "w") {
print "w"
}
} # <-- line 114
replot
}
The output shows the correct key pressed, for example:
MOUSE_KEY = 119
MOUSE_CHAR = "w"
or
MOUSE_KEY = 114
MOUSE_CHAR = "r"
But immediately after I get
"hrtp.gp" line 114: Non-numeric string found where a numeric expression was expected
The test for string equality is eq
not ==
, so you want if (MOUSE_CHAR eq "w") { print "w" }
.