Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the platform specific scancode available #2294

Merged
merged 4 commits into from Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -1090,7 +1090,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 @@ -1118,8 +1118,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 @@ -1166,9 +1166,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 = ""
)