andlabs / ui

Platform-native GUI library for Go.
Other
8.34k stars 653 forks source link

Feature request: keyboard events from Window (keyboard shortcuts) #66

Open andres-erbsen opened 9 years ago

andres-erbsen commented 9 years ago

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.

andlabs commented 9 years ago

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.)

andres-erbsen commented 9 years ago

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...).

andlabs commented 6 years ago

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...

ghost commented 4 years ago

@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 commented 4 years ago

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