MouseAndKeyInput (Linux: XTestFakeKeyEvent), no key up event with certain keys
- Lazarus/FPC Version: Lazarus 2.3.0 (rev main-2_3-1602-gdb285860) FPC 3.3.1 x86_64-linux-gtk2
- Operating System: Linux Mint 20.1 Mate
- CPU / Bitness: x86_64
What happens
KeyInput.Press(VK_INSERT)
and KeyInput.Up(VK_INSERT)
both generate a continuing sequence of VK_INSERT
down events.
Same is true for other values such as VK_DELETE
and VK_NEXT
but not with letters such as VK_A
.
This is bug is not often encountered. Only 1 of 13 other distros displayed the same problem in a test performed by dbannon.
What did you expect
Press(VK_INSERT)
should generate a single key down event followed by a single key up event.
Steps to reproduce
Try showkeys
program showkeys2.zip, corrected version.
Solution
Change is_press
type from Boolean
to Boolean32
in XTestFakeKeyEvent
declaration in XKeyInput
:
function XTestFakeKeyEvent(dpy: PDisplay; keycode: dword; is_press: Boolean32;
delay: dword): longint; cdecl; external;
Rationale
The current declaration of XTestFakeKeyEvent
in Xtest.c is
int XTestFakeKeyEvent(Display *dpy, unsigned int keycode, Bool is_press, unsigned long delay) {...
Bool
is a macro for int
defined in XLib.h. Since int
and unsigned int
are usually the same size and since the keycode
type in the Pascal declaration is dword
(32 bits), would it not make sense to declare is_press
as a 32 bit boolean also?
Credit
bytesbites in an August 16, 2016 Lazarus forum post and issue #27819 by delfion. Many thanks to dbannon for all the work on this issue.