KeyChord Events No Longer Working
Describe the bug
Version: cogentcore.org/core v0.3.10
Previously adding an OnFirst key chord handler was working, I was able to intercept a key press and act accordingly. Now it appears that the event is swallowed, of note the event debug does log attempts to find a button with the pressed key to see if it's a shortcut or not.
Shortcut chord: f -- looking for button
Shortcut chord: l -- looking for button
Shortcut chord: k -- looking for button
The strange thing is that an app I created with an earlier version of Cogent still behaves correctly. However in the console debugging events logs errors about replacing old shortcuts. This is logged for keys that I have NOT added handlers for, IE: F10
These errors are also not logged EVERY time I tried to test this, just sometimes.
How to reproduce
- Run the example minimal reproduction code
- Press the any key
- Observe no console log to indicate the event was triggered
- Observe no snackbar presented to indicate the event was triggered
Example code
package main
import (
"cogentcore.org/core/core"
"cogentcore.org/core/events"
"fmt"
)
func main() {
b := core.NewBody("Weirdness Reproducer V0.1")
core.NewText(b).SetText("Hello, World!")
core.MessageSnackbar(b, "Hello World!")
b.OnFirst(events.KeyChord, func(e events.Event) {
fmt.Println("event!")
core.MessageSnackbar(b, "Event!")
})
b.RunMainWindow()
}
Relevant output
Platform
Linux
I restored my changes (which included a version bump to see if that might resolve the issue, and got these errors again. Perhaps something related to versioning?
2025/04/25 15:01:56 ERROR Events.AddShortcut: overwriting duplicate shortcut shortcut=Control+Alt+R originalButton=/scene/func-button-2 newButton=/scene/func-button-2 2025/04/25 15:01:56 ERROR Events.AddShortcut: overwriting duplicate shortcut shortcut=Control+Alt+R originalButton=/scene/func-button-2 newButton=/scene/func-button-2 2025/04/25 15:01:56 ERROR Events.AddShortcut: overwriting duplicate shortcut shortcut=Control+Alt+R originalButton=/scene/func-button-2 newButton=/scene/func-button-2 2025/04/25 15:01:57 ERROR Events.AddShortcut: overwriting duplicate shortcut shortcut=Control+Alt+R originalButton=/scene/func-button-2 newButton=/scene/func-button-2 2025/04/25 15:01:57 ERROR Events.AddShortcut: overwriting duplicate shortcut shortcut=Control+Alt+R originalButton=/scene/func-button-2 newButton=/scene/func-button-2
@DapperMongoose Thank you for filing this issue. I can reproduce the issue, although when I double click on the text to ensure that the body has focus, then the event handling works after that. Therefore, it seems like this issue is about the body not having focus in the first place; nobody is swallowing the event per se; rather, the body doesn't have access to it at all.
I will look into this issue more at some point, but you can add a b.SetFocusQuiet() call right after you make the body as a workaround in the meantime. Please let me know if that workaround does not work.
Sorry, I forgot to respond to this one, I was able to restore the functionality using that workaround.