io/key: implement key.Release state

Implement key state for the following platforms:
js, wayland, windows, x11.

Unsupported platforms will continue to function as before, sending
key.Press for all key events.

Signed-off-by: Josiah Niedrauer <josiah@niedrauer.com>
This commit is contained in:
Josiah Niedrauer
2020-10-29 15:46:41 -07:00
committed by Elias Naur
parent ef652f4922
commit 42e568775c
7 changed files with 57 additions and 14 deletions
+3 -2
View File
@@ -150,7 +150,7 @@ func (x *Context) Modifiers() key.Modifiers {
return mods
}
func (x *Context) DispatchKey(keyCode uint32) (events []event.Event) {
func (x *Context) DispatchKey(keyCode uint32, state key.State) (events []event.Event) {
if x.state == nil {
return
}
@@ -163,6 +163,7 @@ func (x *Context) DispatchKey(keyCode uint32) (events []event.Event) {
cmd := key.Event{
Name: name,
Modifiers: x.Modifiers(),
State: state,
}
// Ensure that a physical backtab key is translated to
// Shift-Tab.
@@ -201,7 +202,7 @@ func (x *Context) DispatchKey(keyCode uint32) (events []event.Event) {
str = str[:len(str)-s]
}
}
if len(str) > 0 {
if state == key.Press && len(str) > 0 {
events = append(events, key.EditEvent{Text: string(str)})
}
return