I don't know how I have the bad luck to find such obscure bugs, but I found that in console mode under Linux (this bug is likely specific to the Linux GPM GETMOUSE implementation), calling INKEY at a moment that the mouse is being moved, after having previously called LOCATE with only a row, not a column number, and having called GETMOUSE causes INKEY to start producing a stream of garbage characters, and additionally breaks GETMOUSE (it returns 0,0). It seems that all three functions have to be called to cause the bug.
cls
while true
locate 5 'Causes bug
'locate 5,1 'Doesn't cause bug
dim as integer x,y
getmouse x, y
? x & "," & y, inkey
sleep 1
wend
fb_ConsoleGetMouse()has two possible sources of data: GPM in case of TERM=linux, or terminal escape sequences in case of TERM=xterm. I'm also seeing the bug with the xterm case. (I can't even test the GPM case though, because FB looks for libgpm.so.1 and Ubuntu has libgpm.so.2, so getmouse doesn't work at all in that case.)Last edit: dkl 2022-10-03
I think the problem is
fb_hTermQuery()- it can read and skip escape codes received from the terminal, while waiting for its expected response. The problem is that it will silently drop unexpected escape codes, such as (presumably) those for GETMOUSE, which would normally be handled by the INKEY mechanism (look forKEY_MOUSE).That should be relatively easy to fix, I might try to make a patch for this later... But another question is, why does
fb_hTermQuery()read from stdin directly in the first place, instead of using__fb_con.keyboard_getch()orfb_hGetCh()like everything else?Sorry, yes, I was wrong to mention GPM. I forgot that GPM is used for Linux ttys, not xterm-compatible emulators. I noticed the mouse wasn't working in a Linux tty but neglected to mention that. I actually tested for & see the bug under xfce4-terminal, xterm and konsole (except that even when the bug isn't triggered, konsole only updates the reported the mouse position while a mouse button is down).
Also, instead of using INKEY, here's an alternative testcase using GETKEY. Moving the mouse causes spurious keypresses and breaks GETMOUSE.
(Off-topic, but how come fb_KeyHit isn't exposed as a keyword or at least in a header? It's very useful)