2
0
mirror of https://github.com/OrbTools/OrbBind synced 2024-11-17 09:25:55 +00:00
OrbBind/keys/keys.go

61 lines
2.1 KiB
Go
Raw Normal View History

2021-05-03 19:00:08 +00:00
package keys
import (
2021-05-12 02:07:44 +00:00
"strings"
2021-05-03 19:00:08 +00:00
2021-05-12 02:07:44 +00:00
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver/desktop"
"github.com/OrbTools/OrbCommon/hid"
2022-02-02 05:55:17 +00:00
"github.com/OrbTools/OrbCommon/hid/structs"
2021-05-03 19:00:08 +00:00
)
2022-02-02 05:55:17 +00:00
func FyneToKeymap(e *fyne.KeyEvent) structs.Key {
2021-05-12 02:07:44 +00:00
switch e.Name {
case fyne.Key0, fyne.Key1, fyne.Key2, fyne.Key3, fyne.Key4, fyne.Key5, fyne.Key6, fyne.Key7, fyne.Key8, fyne.Key9:
2021-05-12 02:07:44 +00:00
return hid.GetMappingFromName("DIGIT" + string(e.Name))
case fyne.KeyF1, fyne.KeyF2, fyne.KeyF3, fyne.KeyF4, fyne.KeyF5, fyne.KeyF6, fyne.KeyF7, fyne.KeyF8, fyne.KeyF9, fyne.KeyF10, fyne.KeyF11, fyne.KeyF12:
2021-05-12 02:07:44 +00:00
return hid.GetMappingFromName(string(e.Name))
case fyne.KeyLeft, fyne.KeyRight, fyne.KeyUp, fyne.KeyDown:
2021-05-12 02:07:44 +00:00
return hid.GetMappingFromName("ARROW_" + strings.ToUpper(string(e.Name)))
2021-06-04 22:14:54 +00:00
case fyne.KeyBackspace, fyne.KeyEscape, fyne.KeySpace:
2021-05-12 02:07:44 +00:00
return hid.GetMappingFromName(strings.ToUpper(string(e.Name)))
2021-06-04 22:14:54 +00:00
case fyne.KeyBackslash:
return hid.GetMappingFromName("BACKSLASH")
2022-02-03 00:51:31 +00:00
case fyne.KeySlash:
return hid.GetMappingFromName("SLASH")
2021-06-04 22:14:54 +00:00
case fyne.KeyBackTick:
return hid.GetMappingFromName("BACKQUOTE")
case fyne.KeyMinus:
return hid.GetMappingFromName("MINUS")
case fyne.KeyEqual:
return hid.GetMappingFromName("EQUAL")
case fyne.KeySemicolon:
return hid.GetMappingFromName("SEMICOLON")
2021-05-12 02:07:44 +00:00
case fyne.KeyReturn:
return hid.GetMappingFromName("ENTER")
case desktop.KeyAltLeft:
return hid.GetMappingFromName("ALT_LEFT")
case desktop.KeyAltRight:
return hid.GetMappingFromName("ALT_RIGHT")
case desktop.KeyControlLeft:
return hid.GetMappingFromName("CONTROL_LEFT")
case desktop.KeyControlRight:
return hid.GetMappingFromName("CONTROL_RIGHT")
case desktop.KeyShiftLeft:
return hid.GetMappingFromName("SHIFT_LEFT")
case desktop.KeyShiftRight:
return hid.GetMappingFromName("SHIFT_RIGHT")
case fyne.KeyTab:
return hid.GetMappingFromName("TAB")
2022-02-03 00:50:05 +00:00
case fyne.KeyComma:
return hid.GetMappingFromName("COMMA")
2021-05-12 02:07:44 +00:00
default:
return hid.GetMappingFromName("US_" + strings.ToUpper(string(e.Name)))
2021-05-03 19:00:08 +00:00
}
//return hid.GetMappingFromName("USB_RESERVED")
2021-05-03 19:00:08 +00:00
}
2022-02-02 05:55:17 +00:00
func KeyFromEvdev(b uint16) structs.Key {
2021-05-12 02:07:44 +00:00
return hid.GetMappingFromLinux(b)
2021-05-03 19:00:08 +00:00
}