Tk Source Code

View Ticket
Login
Ticket UUID: d3b9644729ba521cc75aa4cd7068e5e7f6e08e01
Title: X11 <KeyRelease> broken
Type: Bug Version: 8.6.12
Submitter: xolodho Created on: 2022-09-12 23:08:53
Subsystem: 69. Events Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-10-11 12:39:37
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-09-28 11:06:59
Description:
On X11, Tk's <KeyRelease> is not working properly. Or perhaps
<KeyPress> and <KeyRelease> are both buggy, I don't know.

For instance with this code :

 bind . <KeyPress> {puts "%# KeyPress %K"}
 bind . <KeyRelease> {puts "%# KeyRelease %K"}

On X11 while I hold down some key, that prints a stream of alternated
KeyPress and KeyRelease lines, but the proper behaviour should be a
unique <KeyRelease> after each <KeyPress> repeated sequence, for each
physical key down/up pair, with the <KeyRelease> sent exactly when
the key is released. There was a similar bug reported for MacOSX some
years ago. It works correctly on Win32.

I noticed this odd behavior on several Linux X11 desktops, also on X11
on NetBSD, they all have the same issue (always under Tk 8.6.12).

****************

I found this bug while playing around with Tk's classic buttons, where
I also discovered *another* bug regarding spacebar keypress (the
button looks "stuck" after a while of depressing the spacebar). Some
comments here:

 https://groups.google.com/g/comp.lang.tcl/c/nf2mgqaul1E
User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-09-28 11:06:59:

Many thanks, Serhiy! Merged to main, core-9-0-branch, and core-8-6-branch by commits [cd8ac5d1], [5d9e65a9], and [84526332]. Closing the ticket.


serhiy.storchaka added on 2026-09-19 08:20:53:

Reproduced: the X server sends a KeyRelease/KeyPress pair for each auto-repeat unless the client enables detectable auto-repeat, which Tk did not do. Fix in branch [6d0c31fd56]: XkbSetDetectableAutoRepeat() is called when the display is opened, so a held key generates repeated KeyPress events and a single KeyRelease, as on Windows and macOS.