2
0
mirror of https://github.com/OrbTools/OrbBind synced 2024-10-31 03:20:26 +00:00

further port to Fyne v2

This commit is contained in:
Minizbot2012 2021-05-11 22:07:44 -04:00
parent 80b68f1c39
commit c0be090594

View File

@ -1,45 +1,70 @@
package keys
import (
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver/desktop"
"github.com/OrbTools/OrbCommon/hid"
)
var (
//KCToASCII keycode to ascii table
KCToASCII map[Code]rune
)
//GetASCIIForSC Returns Ascii for Scancode
func GetASCIIForSC(r uint16) uint16 {
return uint16(KCToASCII[Code(r)])
}
//GetSCForASCII Returns scancode For Ascii
func GetSCForASCII(r uint16) uint16 {
return uint16(ASCIIToKC[rune(r)])
}
func init() {
KCToASCII = make(map[Code]rune)
for x, y := range ASCIIToKC {
KCToASCII[y] = x
func FyneToKeymap(e *fyne.KeyEvent) hid.Key {
switch e.Name {
case fyne.Key0:
case fyne.Key1:
case fyne.Key2:
case fyne.Key3:
case fyne.Key4:
case fyne.Key5:
case fyne.Key6:
case fyne.Key7:
case fyne.Key8:
case fyne.Key9:
return hid.GetMappingFromName("DIGIT" + string(e.Name))
case fyne.KeyF1:
case fyne.KeyF2:
case fyne.KeyF3:
case fyne.KeyF4:
case fyne.KeyF5:
case fyne.KeyF6:
case fyne.KeyF7:
case fyne.KeyF8:
case fyne.KeyF9:
case fyne.KeyF10:
case fyne.KeyF11:
case fyne.KeyF12:
return hid.GetMappingFromName(string(e.Name))
case fyne.KeyLeft:
case fyne.KeyRight:
case fyne.KeyUp:
case fyne.KeyDown:
return hid.GetMappingFromName("ARROW_" + strings.ToUpper(string(e.Name)))
case fyne.KeyBackspace:
case fyne.KeyBackslash:
case fyne.KeyEscape:
return hid.GetMappingFromName(strings.ToUpper(string(e.Name)))
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")
default:
return hid.GetMappingFromName("US_" + strings.ToUpper(string(e.Name)))
}
return hid.GetMappingFromName("USB_RESERVED")
}
//CKIFyneKeyMap Control Keys interop
func CKIFyneKeyMap(e fyne.KeyName) uint16 {
if val, ok := FyneToKC[e]; ok {
return uint16(val)
}
return 0
}
//CKIKeyNameFromKC Key Name from Keycode
func CKIKeyNameFromKC(r uint16) string {
return Code(r).String()[4:]
}
//CKIKeyNameFromASCII key name from ascii code
func CKIKeyNameFromASCII(r uint16) string {
return ASCIIToKC[rune(r)].String()[4:]
func KeyFromEvdev(b uint16) hid.Key {
return hid.GetMappingFromLinux(b)
}