How to listen for keyboard events #5316
-
I have built an app that consists of a TextGrid, and I want it to listen to keyboard events. The code is this: terminal := widget.NewTextGrid()
terminal.SetText("Some Text")
container := fyne_container.NewMax(terminal)
window.SetContent(container) I've tried these, but none of them work:
This is the console output:
I think this may be an installation problem. I installed it using these commands:
Here is my complete code: package main
import (
"fmt"
"fyne.io/fyne/v2"
fyne_app "fyne.io/fyne/v2/app"
fyne_container "fyne.io/fyne/v2/container"
fyne_widget "fyne.io/fyne/v2/widget"
)
var input_text = ""
func main() {
// Window
app := fyne_app.New()
window := app.NewWindow("Terminal")
window.Resize(fyne.NewSize(800, 600))
// Terminal
terminal := fyne_widget.NewTextGrid()
terminal.TabWidth = 4
terminal.SetText("Some Text")
// Keyboard Listen (problem)
//> terminal.SetOnTypedKey = func(key *fyne.KeyEvent) {
//> fmt.Println(key.Name)
//> }
// Full Window
container := fyne_container.NewMax(terminal)
window.SetContent(container)
// Run
window.ShowAndRun()
} Who can help me solve this? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Correct, those APIs don't exist. To have a widget respond to events you need to implement the handlers by extending. See docs at: |
Beta Was this translation helpful? Give feedback.
Correct, those APIs don't exist.
To have a widget respond to events you need to implement the handlers by extending. See docs at:
https://docs.fyne.io/extend/extending-widgets