diff --git a/main.go b/main.go index 9cb778b..bbbea2f 100644 --- a/main.go +++ b/main.go @@ -49,7 +49,10 @@ func main() { ui.MainWindow.SetWindowTitle(os.Args[1] + " - " + appName) ui.infoArea.AddItem(fmt.Sprintf("Sorting %d entries", len(entries))) + ui.infoArea.AddItem("Use [Q] and [Z] to select with the keyboard") + ui.infoArea.ScrollToBottom() + active := true ret := make(chan bool, 0) ui.b1.OnClicked(func() { // Set up click handlers only once ret <- true @@ -58,8 +61,29 @@ func main() { ret <- false }) + ui.MainWindow.OnKeyPressEvent(func(super func(event *qt.QKeyEvent), event *qt.QKeyEvent) { + if !active { + super(event) + return + } + + keytext := strings.ToLower(event.Text()) + if keytext == `q` { + ret <- true + + } else if keytext == `z` { + ret <- false + + } else { // not our event + super(event) + } + + }) + ui.MainWindow.Show() + ui.infoArea.SetFocusPolicy(qt.NoFocus) // prevent stealing keyboard input + comparisons := 0 go func() { @@ -78,6 +102,7 @@ func main() { return <-ret }) + active = false mainthread.Start(func() { ui.b1.SetEnabled(false)