Kitty: hotkey involving upper case letter
I have a DataTable TUI that takes multi key sequences as shortcut. It's no longer working with the latest version of Textual (8.2.8) in the Ghostty terminal, which supports the Kitty protocol.
g + H now is translated into g + left_shift + h
# kitty.py
from textual.app import App
from textual import events
class MyApp(App):
def __init__(self):
super().__init__()
self.waiting_for_h = False
def on_key(self, event: events.Key) -> None:
if event.key == "g":
self.waiting_for_h = True
return
if self.waiting_for_h:
self.waiting_for_h = False
if event.key == "H":
self.notify("Shortcut g, then Shift+H!")
return
if __name__ == "__main__":
MyApp().run()
Reproduction:
- Run under Ghostty on macOS.
- Press g, followed by Shift+H.
- The binding fails.
- Run with TEXTUAL_DISABLE_KITTY_KEY=1.
- The binding works.
We found the following entry in the FAQ which you may find helpful:
Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.
This project is developed and maintained by Will McGugan. Consider sponsoring Will's work on this project (and others).
This is an automated reply, generated by FAQtory
I can reproduce the cause with Textual 8.2.8 (no Ghostty here, so I fed the Kitty sequences to Textual's parser and replayed the keys in run_test).
Since #6544, Textual turns on the Kitty "report all keys as escape codes" flag. With it, the terminal also reports a modifier key on its own. Pressing Shift+H gives two key events:
| Sequence | event.key |
|---|---|
ESC[57441;2u (Shift pressed) |
left_shift |
ESC[104;2;72u (h with Shift, text "H") |
H |
So H itself still arrives as H. The extra left_shift event comes first, and your on_key treats it as "the next key", so it clears waiting_for_h before H arrives.
A workaround is to skip modifier keys in the handler:
MODIFIER_KEYS = {
f"{side}_{mod}"
for side in ("left", "right")
for mod in ("shift", "control", "alt", "super", "hyper", "meta")
}
def on_key(self, event: events.Key) -> None:
if event.key in MODIFIER_KEYS:
return
... # your g / H logic unchanged
Result with pilot.press(...) on your app:
| Keys | Original | With the skip |
|---|---|---|
g, H |
fires | fires |
g, left_shift, H (what Ghostty sends) |
does not fire | fires |
TEXTUAL_DISABLE_KITTY_KEY=1 also works, as you found, but it turns off the other Kitty key fixes too.
Thanks for the hint. I'll give it a try soon.
It works. Thanks again.
I hope I solved your issue!
Consider sponsoring my work to continue to maintain and develop Textual.
- Will McGugan