diff --git a/hid/hid.go b/hid/hid.go new file mode 100644 index 0000000..d9904e1 --- /dev/null +++ b/hid/hid.go @@ -0,0 +1,42 @@ +package hid + +type KeyMaps struct { + Usb map[uint16]Key + Evdev map[uint16]Key + Xkb map[uint16]Key + Win map[uint16]Key + Mac map[uint16]Key + Code map[string]Key + Arr []Key +} + +type Key struct { + Usb uint16 + Evdev uint16 + Xkb uint16 + Win uint16 + Mac uint16 + Code string +} + +var Mappings KeyMaps = KeyMaps{} + +func GetMappingFromHID(uv uint16) Key { + return Mappings.Usb[uv] +} + +func GetMappingFromWindows(uv uint16) Key { + return Mappings.Win[uv] +} + +func GetMappingFromLinux(uv uint16) Key { + return Mappings.Evdev[uv] +} + +func GetMappingFromName(name string) Key { + return Mappings.Code[name] +} + +func GetMappingFromX(code uint16) Key { + return Mappings.Xkb[code] +} diff --git a/hid/hid_json.go b/hid/hid_json.go index 2842d21..1c77ca2 100644 --- a/hid/hid_json.go +++ b/hid/hid_json.go @@ -13,23 +13,3 @@ var file []byte func init() { json.Unmarshal(file, &Mappings) } - -func GetMappingFromHID(uv uint16) Key { - return Mappings.Usb[uv] -} - -func GetMappingFromWindows(uv uint16) Key { - return Mappings.Win[uv] -} - -func GetMappingFromLinux(uv uint16) Key { - return Mappings.Evdev[uv] -} - -func GetMappingFromName(name string) Key { - return Mappings.Code[name] -} - -func GetMappingFromX(code uint16) Key { - return Mappings.Xkb[code] -} diff --git a/hid/hid_xdr.go b/hid/hid_xdr.go index 187bbc8..61f468c 100644 --- a/hid/hid_xdr.go +++ b/hid/hid_xdr.go @@ -8,50 +8,9 @@ import ( xdr "github.com/davecgh/go-xdr/xdr2" ) -type KeyMaps struct { - Usb map[uint16]Key - Evdev map[uint16]Key - Xkb map[uint16]Key - Win map[uint16]Key - Mac map[uint16]Key - Code map[string]Key - Arr []Key -} - -type Key struct { - Usb uint16 - Evdev uint16 - Xkb uint16 - Win uint16 - Mac uint16 - Code string -} - -var Mappings KeyMaps = KeyMaps{} - //go:embed generated.bin var file []byte func init() { xdr.Unmarshal(bytes.NewReader(file), Mappings) } - -func GetMappingFromHID(uv uint16) Key { - return Mappings.Usb[uv] -} - -func GetMappingFromWindows(uv uint16) Key { - return Mappings.Win[uv] -} - -func GetMappingFromLinux(uv uint16) Key { - return Mappings.Evdev[uv] -} - -func GetMappingFromName(name string) Key { - return Mappings.Code[name] -} - -func GetMappingFromX(code uint16) Key { - return Mappings.Xkb[code] -}