ui icon indicating copy to clipboard operation
ui copied to clipboard

Feature request: keyboard events from Window (keyboard shortcuts)

Open andres-erbsen opened this issue 10 years ago • 5 comments

It would be great if there was a way to detect keyboard when the application window has focus, not just when an Area has focus. The use cases I have in mind.

  • Enter to execute/start/send something
  • Ctrl-O to open an external file picker

andres-erbsen avatar Dec 16 '14 23:12 andres-erbsen

Keyboard shortcuts will come when I figure out how to do menu syntax; the two will be tied together. (I'm not sure what a good syntax would be; if you have any ideas let me know.)

andlabs avatar Dec 17 '14 03:12 andlabs

Here is an idea of mine, loosely based on the corresponding Qt Quick interface.

type MenuItem struct { // this would be in package ui
    Name      string
    Image      image.Image
    Modifiers ui.Modifiers
    Key       byte
    Handler   func()
    Submenu   []MenuItem
}

var mainMenu = NewMenu([]MenuItem{
    {"File", nil, ui.Alt, 'f', nil, []MenuItem{
        {"Open", nil, ui.Ctrl, 'o', func() { println("LaunchFilePicker()") }, nil},
        {"Quit", nil, ui.Ctrl | ui.Shift, 'q', ui.Stop, nil},
    }},
    {"About", nil, ui.Alt, 'a', func() { println("written by me") }, nil},
})

One weakness of this approach is that adding a new property to MenuItem would break all code written this way (using field names in the literals would help...).

andres-erbsen avatar Dec 17 '14 06:12 andres-erbsen

Ctrl-O is now andlabs/libui#321.

Enter on a window is a different thing I have to think about under what conditions it doesn't Just Work...

andlabs avatar Mar 25 '18 22:03 andlabs

@andlabs if windows part is the only issue preventing you from implementing key events handling in the entry i have it in the libui part. ~But i'm struggling with the go ui binding. Could you have a look if you have time so we can merge our knowledge and get this feature done~ Looks like i've found an issue

ghost avatar Mar 03 '20 10:03 ghost

https://github.com/RustamGamidov/ui/tree/entry_keyEvent https://github.com/RustamGamidov/libui/tree/entry_keyEvent

ghost avatar Mar 03 '20 10:03 ghost