From 293eb5981b8fbd1522f3fe8714f87013eb5b2069 Mon Sep 17 00:00:00 2001 From: Minizbot2012 Date: Thu, 29 Apr 2021 20:34:26 -0400 Subject: [PATCH] *TEST REL* MAY BREAK WINDOWS --- devices/orbweaver/orbweaver_linux.go | 12 +++++------- devices/orbweaver/orbweaver_windows.go | 8 ++++---- emu/emu_linux.go | 6 +++--- emu/emu_windows.go | 4 ++-- go.mod | 3 ++- go.sum | 6 ++++-- interface/keyevents/keyevents.go | 8 -------- main.go | 4 ++-- 8 files changed, 22 insertions(+), 29 deletions(-) delete mode 100644 interface/keyevents/keyevents.go diff --git a/devices/orbweaver/orbweaver_linux.go b/devices/orbweaver/orbweaver_linux.go index 39dadab..a836d71 100644 --- a/devices/orbweaver/orbweaver_linux.go +++ b/devices/orbweaver/orbweaver_linux.go @@ -5,28 +5,26 @@ package orbweaver import ( "bytes" "encoding/binary" - "os" morb "github.com/OrbTools/OrbCommon/devices/orbweaver" - "github.com/OrbTools/OrbMap/interface/keyevents" + evdev "github.com/gvalkov/golang-evdev" ) //OrbLoop Main loop for this device -func OrbLoop(km *morb.KeyMaps, KeyBus chan keyevents.KeyEvent) { +func OrbLoop(km *morb.KeyMaps, KeyBus chan *evdev.InputEvent) { eventcodes = morb.BINDING[:] for i := 0; i < len(eventcodes); i++ { ecm[uint16(eventcodes[i])] = i } println("UnixLoop starting") - f, err := os.Open("/dev/input/by-id/usb-Razer_Razer_Orbweaver_Chroma-event-kbd") + f, err := evdev.Open("/dev/input/by-id/usb-Razer_Razer_Orbweaver_Chroma-event-kbd") if err != nil { panic(err) } - defer f.Close() + f.Grab() b := make([]byte, 24) for { - f.Read(b) - KeyEv := keyevents.KeyEvent{} + KeyEv, _ := f.ReadOne() binary.Read(bytes.NewReader(b[16:]), binary.LittleEndian, &KeyEv) KeyEv.Code = km.Maps[km.Currentmap].Keymap[ecm[KeyEv.Code]] if KeyEv.Code != 0 && KeyEv.Type != 4 { diff --git a/devices/orbweaver/orbweaver_windows.go b/devices/orbweaver/orbweaver_windows.go index 5645ff9..8830d61 100644 --- a/devices/orbweaver/orbweaver_windows.go +++ b/devices/orbweaver/orbweaver_windows.go @@ -9,8 +9,8 @@ import ( morb "github.com/OrbTools/OrbCommon/devices/orbweaver" "github.com/OrbTools/OrbCommon/hid" - "github.com/OrbTools/OrbMap/interface/keyevents" "github.com/google/gousb" + evdev "github.com/gvalkov/golang-evdev" ) const ( @@ -101,7 +101,7 @@ func (s *swapInt) Differ(s2 *swapInt) []byte { } //OrbLoop Main loop for this device -func OrbLoop(km *morb.KeyMaps, KeyBus chan keyevents.KeyEvent) { +func OrbLoop(km *morb.KeyMaps, KeyBus chan *evdev.InputEvent) { eventcodes = morb.BINDING[:] for i := 0; i < len(eventcodes); i++ { ecm[uint16(eventcodes[i])] = i @@ -163,7 +163,7 @@ func OrbLoop(km *morb.KeyMaps, KeyBus chan keyevents.KeyEvent) { } for _, pre := range swaper.S1.Differ(swaper.S2) { if pre != 0 { - KeyEv := keyevents.KeyEvent{} + KeyEv := &evdev.InputEvent{} KeyEv.Code = uint16(pre) KeyEv.Type = 1 KeyBus <- KeyEv @@ -171,7 +171,7 @@ func OrbLoop(km *morb.KeyMaps, KeyBus chan keyevents.KeyEvent) { } for _, rel := range swaper.S2.Differ(swaper.S1) { if rel != 0 { - KeyEv := keyevents.KeyEvent{} + KeyEv := &evdev.InputEvent{} KeyEv.Code = uint16(rel) KeyEv.Type = 2 KeyBus <- KeyEv diff --git a/emu/emu_linux.go b/emu/emu_linux.go index 6d4fb03..48d0e1a 100644 --- a/emu/emu_linux.go +++ b/emu/emu_linux.go @@ -3,14 +3,14 @@ package emu import ( - "github.com/OrbTools/OrbMap/interface/keyevents" "github.com/bendahl/uinput" + evdev "github.com/gvalkov/golang-evdev" ) var vkm uinput.Keyboard = nil //ProcKey keyboard emulator loop -func ProcKey(kb chan keyevents.KeyEvent) { +func ProcKey(kb chan *evdev.InputEvent) { println("Emu Unix Starting") var err error vkm, err = uinput.CreateKeyboard("/dev/uinput", []byte("Orbmap")) @@ -20,7 +20,7 @@ func ProcKey(kb chan keyevents.KeyEvent) { defer vkm.Close() for { KeyEv := <-kb - if KeyEv.Type == 1 { + if KeyEv.Code == 1 { if KeyEv.Value == 1 { vkm.KeyDown(int(KeyEv.Code)) } else if KeyEv.Value == 2 { diff --git a/emu/emu_windows.go b/emu/emu_windows.go index ce2a23a..44c41a6 100644 --- a/emu/emu_windows.go +++ b/emu/emu_windows.go @@ -5,7 +5,7 @@ package emu import ( "unsafe" - "github.com/OrbTools/OrbMap/interface/keyevents" + evdev "github.com/gvalkov/golang-evdev" "github.com/lxn/win" ) @@ -39,7 +39,7 @@ func upKey(key uint16) { } //ProcKey Windows support is so weird -func ProcKey(kb chan keyevents.KeyEvent) { +func ProcKey(kb chan *evdev.InputEvent) { println("Emu Windows Starting") for { KeyEv := <-kb diff --git a/go.mod b/go.mod index 58d295d..35882ae 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/OrbTools/OrbCommon v0.0.0-20210302052644-6a27f15862ae github.com/bendahl/uinput v1.4.1 github.com/google/gousb v1.1.1 + github.com/gvalkov/golang-evdev v0.0.0-20191114124502-287e62b94bcb // indirect github.com/lxn/win v0.0.0-20210218163916-a377121e959e - golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 // indirect + golang.org/x/sys v0.0.0-20210426230700-d19ff857e887 // indirect ) diff --git a/go.sum b/go.sum index 96680c6..383fde7 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,10 @@ github.com/bendahl/uinput v1.4.1 h1:ecxSLcVxWk0EFyZBtmCTnOKjK/HCNdsUcWXRTkNt06k= github.com/bendahl/uinput v1.4.1/go.mod h1:Np7w3DINc9wB83p12fTAM3DPPhFnAKP0WTXRqCQJ6Z8= github.com/google/gousb v1.1.1 h1:2sjwXlc0PIBgDnXtNxUrHcD/RRFOmAtRq4QgnFBE6xc= github.com/google/gousb v1.1.1/go.mod h1:b3uU8itc6dHElt063KJobuVtcKHWEfFOysOqBNzHhLY= +github.com/gvalkov/golang-evdev v0.0.0-20191114124502-287e62b94bcb h1:WHSAxLz3P5t4DKukfJ5wu7+aMyVkuTNSbCiAjVS92sM= +github.com/gvalkov/golang-evdev v0.0.0-20191114124502-287e62b94bcb/go.mod h1:SAzVFKCRezozJTGavF3GX8MBUruETCqzivVLYiywouA= github.com/lxn/win v0.0.0-20210218163916-a377121e959e h1:H+t6A/QJMbhCSEH5rAuRxh+CtW96g0Or0Fxa9IKr4uc= github.com/lxn/win v0.0.0-20210218163916-a377121e959e/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk= golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 h1:iGu644GcxtEcrInvDsQRCwJjtCIOlT2V7IRt6ah2Whw= -golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210426230700-d19ff857e887 h1:dXfMednGJh/SUUFjTLsWJz3P+TQt9qnR11GgeI3vWKs= +golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/interface/keyevents/keyevents.go b/interface/keyevents/keyevents.go deleted file mode 100644 index 8787879..0000000 --- a/interface/keyevents/keyevents.go +++ /dev/null @@ -1,8 +0,0 @@ -package keyevents - -//KeyEvent represents a keyevent -type KeyEvent struct { - Type uint16 - Code uint16 - Value int32 -} diff --git a/main.go b/main.go index 94222ae..22a7170 100644 --- a/main.go +++ b/main.go @@ -6,13 +6,13 @@ import ( "github.com/OrbTools/OrbMap/devices/orbweaver" "github.com/OrbTools/OrbMap/emu" - "github.com/OrbTools/OrbMap/interface/keyevents" + evdev "github.com/gvalkov/golang-evdev" ) func main() { orbs := flag.String("orbweaver", "", "Comma seperated string of orbs for the orbweaver") flag.Parse() - KeyBus := make(chan keyevents.KeyEvent, 128) + KeyBus := make(chan *evdev.InputEvent, 128) Maps := orbweaver.ProcOrbFiles(*orbs) go orbweaver.OrbLoop(Maps, KeyBus) emu.ProcKey(KeyBus)