Skip to content

Commit

Permalink
Merge pull request #2294 from andydotxyz/fix/1523
Browse files Browse the repository at this point in the history
Make the platform specific scancode available
  • Loading branch information
andydotxyz committed Aug 15, 2021
2 parents 9fb0f9e + 7acba69 commit 5304bfa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 10 additions & 0 deletions event.go
@@ -1,8 +1,18 @@
package fyne

// HardwareKey contains information associated with physical key events
// Most applications should use KeyName for cross-platform compatibility.
type HardwareKey struct {
// ScanCode represents a hardware ID for (normally desktop) keyboard events.
ScanCode int
}

// KeyEvent describes a keyboard input event.
type KeyEvent struct {
// Name describes the keyboard event that is consistent across platforms.
Name KeyName
// Physical is a platform specific field that reports the hardware information of physical keyboard events.
Physical HardwareKey
}

// PointEvent describes a pointer input event. The position is relative to the
Expand Down
7 changes: 2 additions & 5 deletions internal/driver/glfw/window.go
Expand Up @@ -1092,7 +1092,7 @@ func keyToName(code glfw.Key, scancode int) fyne.KeyName {
keyName := glfw.GetKeyName(code, scancode)
ret, ok = keyNameMap[keyName]
if !ok {
return ""
return fyne.KeyUnknown
}

return ret
Expand Down Expand Up @@ -1120,8 +1120,8 @@ func (w *window) capturesTab(modifier desktop.Modifier) bool {

func (w *window) keyPressed(_ *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
keyName := keyToName(key, scancode)
keyEvent := &fyne.KeyEvent{Name: keyName, Physical: fyne.HardwareKey{ScanCode: scancode}}

keyEvent := &fyne.KeyEvent{Name: keyName}
keyDesktopModifier := desktopModifier(mods)
pendingMenuToggle := w.menuTogglePending
pendingMenuDeactivation := w.menuDeactivationPending
Expand Down Expand Up @@ -1168,9 +1168,6 @@ func (w *window) keyPressed(_ *glfw.Window, key glfw.Key, scancode int, action g
// key repeat will fall through to TypedKey and TypedShortcut
}

if keyName == "" { // don't emit unknown
return
}
if (keyName == fyne.KeyTab && !w.capturesTab(keyDesktopModifier)) || w.triggersShortcut(keyName, keyDesktopModifier) {
return
}
Expand Down
6 changes: 6 additions & 0 deletions key.go
Expand Up @@ -167,4 +167,10 @@ const (
KeyPlus KeyName = "+"
// KeyBackTick is the key "`" on a US keyboard
KeyBackTick KeyName = "`"

// KeyUnknown is used for key events where the underlying hardware generated an
// event that Fyne could not decode.
//
// Since: 2.1
KeyUnknown KeyName = ""
)

0 comments on commit 5304bfa

Please sign in to comment.