From d2204a8627b87cba2b26f18bf01abc24d077830e Mon Sep 17 00:00:00 2001 From: anoshenko Date: Mon, 29 May 2023 17:19:47 +0300 Subject: [PATCH] Changed the type of KeyEvent.Code field --- keyEvents.go | 5 +++-- popup.go | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/keyEvents.go b/keyEvents.go index 368ff2b..b7ec325 100644 --- a/keyEvents.go +++ b/keyEvents.go @@ -153,7 +153,7 @@ type KeyEvent struct { // Code holds a string that identifies the physical key being pressed. The value is not affected // by the current keyboard layout or modifier state, so a particular key will always return the same value. - Code string + Code KeyCode // Repeat == true if a key has been depressed long enough to trigger key repetition, otherwise false. Repeat bool @@ -180,7 +180,8 @@ func (event *KeyEvent) init(data DataObject) { } event.Key, _ = data.PropertyValue("key") - event.Code, _ = data.PropertyValue("code") + code, _ := data.PropertyValue("code") + event.Code = KeyCode(code) event.TimeStamp = getTimeStamp(data) event.Repeat = getBool("repeat") event.CtrlKey = getBool("ctrlKey") diff --git a/popup.go b/popup.go index ac4ce3d..f60da10 100644 --- a/popup.go +++ b/popup.go @@ -622,8 +622,8 @@ func (popup *popupData) onDismiss() { func (popup *popupData) keyEvent(event KeyEvent) bool { if !event.AltKey && !event.CtrlKey && !event.ShiftKey && !event.MetaKey { - switch strings.ToLower(event.Code) { - case "enter": + switch event.Code { + case EnterKey: for _, button := range popup.buttons { if button.Type == DefaultButton && button.OnClick != nil { button.OnClick(popup) @@ -631,7 +631,7 @@ func (popup *popupData) keyEvent(event KeyEvent) bool { } } - case "escape": + case EscapeKey: if popup.cancelable { popup.Dismiss() return true