2
0
mirror of https://github.com/OrbTools/OrbMap synced 2024-11-15 18:13:58 +00:00
This commit is contained in:
Minizbot2012 2021-05-03 15:00:15 -04:00
parent 14bb7f95af
commit 328120d448
No known key found for this signature in database
GPG Key ID: 977C8ADE12361917
8 changed files with 367 additions and 367 deletions

6
.github/FUNDING.yml vendored
View File

@ -1,3 +1,3 @@
# These are supported funding model platforms
github: [minizbot2012]
# These are supported funding model platforms
github: [minizbot2012]

View File

@ -1,36 +1,36 @@
package orbweaver
import (
"fmt"
"path/filepath"
"strings"
morb "github.com/OrbTools/OrbCommon/devices/orbweaver"
)
var eventcodes []byte
var ecm map[uint16]int
func init() {
ecm = make(map[uint16]int)
}
//ProcOrbFiles processes orbs
func ProcOrbFiles(orbs string) *morb.KeyMaps {
keymaps := &morb.KeyMaps{Currentmap: 0}
if len(orbs) > 0 {
for idx, orb := range strings.Split(orbs, ";") {
abs, err := filepath.Abs(orb)
if err != nil {
panic(err)
}
fmt.Println("Loading Orb " + abs)
KMap := morb.LoadKM(abs)
keymaps.Maps[idx] = KMap
}
keymaps.MCount = len(orbs)
} else {
panic("No orbs")
}
return keymaps
}
package orbweaver
import (
"fmt"
"path/filepath"
"strings"
morb "github.com/OrbTools/OrbCommon/devices/orbweaver"
)
var eventcodes []byte
var ecm map[uint16]int
func init() {
ecm = make(map[uint16]int)
}
//ProcOrbFiles processes orbs
func ProcOrbFiles(orbs string) *morb.KeyMaps {
keymaps := &morb.KeyMaps{Currentmap: 0}
if len(orbs) > 0 {
for idx, orb := range strings.Split(orbs, ";") {
abs, err := filepath.Abs(orb)
if err != nil {
panic(err)
}
fmt.Println("Loading Orb " + abs)
KMap := morb.LoadKM(abs)
keymaps.Maps[idx] = KMap
}
keymaps.MCount = len(orbs)
} else {
panic("No orbs")
}
return keymaps
}

View File

@ -1,38 +1,38 @@
// +build linux !windows
package orbweaver
import (
"bytes"
"encoding/binary"
"unsafe"
morb "github.com/OrbTools/OrbCommon/devices/orbweaver"
"github.com/OrbTools/OrbMap/keyevents"
evdev "github.com/gvalkov/golang-evdev"
)
//OrbLoop Main loop for this device
func OrbLoop(km *morb.KeyMaps, KeyBus chan *keyevents.KeyEvent) {
eventcodes = morb.BINDING[:]
for i := 0; i < len(eventcodes); i++ {
ecm[uint16(eventcodes[i])] = i
}
println("UnixLoop starting")
f, err := evdev.Open("/dev/input/by-id/usb-Razer_Razer_Orbweaver_Chroma-event-kbd")
if err != nil {
panic(err)
}
f.Grab()
var evsize = int(unsafe.Sizeof(keyevents.KeyEvent{}))
b := make([]byte, evsize)
for {
f.File.Read(b)
KeyEv := &keyevents.KeyEvent{}
binary.Read(bytes.NewBuffer(b), binary.LittleEndian, KeyEv)
KeyEv.Code = km.Maps[km.Currentmap].Keymap[ecm[KeyEv.Code]]
if KeyEv.Code != 0 && KeyEv.Type != 4 {
KeyBus <- KeyEv
}
}
}
// +build linux !windows
package orbweaver
import (
"bytes"
"encoding/binary"
"unsafe"
morb "github.com/OrbTools/OrbCommon/devices/orbweaver"
"github.com/OrbTools/OrbMap/keyevents"
evdev "github.com/gvalkov/golang-evdev"
)
//OrbLoop Main loop for this device
func OrbLoop(km *morb.KeyMaps, KeyBus chan *keyevents.KeyEvent) {
eventcodes = morb.BINDING[:]
for i := 0; i < len(eventcodes); i++ {
ecm[uint16(eventcodes[i])] = i
}
println("UnixLoop starting")
f, err := evdev.Open("/dev/input/by-id/usb-Razer_Razer_Orbweaver_Chroma-event-kbd")
if err != nil {
panic(err)
}
f.Grab()
var evsize = int(unsafe.Sizeof(keyevents.KeyEvent{}))
b := make([]byte, evsize)
for {
f.File.Read(b)
KeyEv := &keyevents.KeyEvent{}
binary.Read(bytes.NewBuffer(b), binary.LittleEndian, KeyEv)
KeyEv.Code = km.Maps[km.Currentmap].Keymap[ecm[KeyEv.Code]]
if KeyEv.Code != 0 && KeyEv.Type != 4 {
KeyBus <- KeyEv
}
}
}

View File

@ -1,176 +1,176 @@
// +build windows
package orbweaver
import (
"bytes"
"encoding/binary"
"fmt"
morb "github.com/OrbTools/OrbCommon/devices/orbweaver"
"github.com/OrbTools/OrbCommon/hid"
"github.com/OrbTools/OrbMap/keyevents"
"github.com/google/gousb"
)
const (
vendor = gousb.ID(0x1532)
prod = gousb.ID(0x0207)
leftControl byte = 0x1
leftShift byte = 0x2
leftAlt byte = 0x4
)
type swaps struct {
S1 *swapInt
S2 *swapInt
}
type swapInt struct {
K1 byte
K2 byte
K3 byte
K4 byte
K5 byte
K6 byte
K7 byte
K8 byte
K9 byte
}
func (s *swapInt) contains(k byte) bool {
return (s.K1 == k || s.K2 == k || s.K3 == k || s.K4 == k || s.K5 == k || s.K6 == k || s.K7 == k || s.K8 == k || s.K9 == k)
}
func (s *swaps) swap() {
ss := s.S1
s.S1 = s.S2
s.S2 = ss
}
func trans(M byte) []byte {
r := make([]byte, 0)
if (M & leftShift) != 0 {
r = append(r, byte(hid.GetMappingFromName("SHIFT_LEFT").Usb))
} else {
r = append(r, 0)
}
if (M & leftControl) != 0 {
r = append(r, byte(hid.GetMappingFromName("CONTROL_LEFT").Usb))
} else {
r = append(r, 0)
}
if (M & leftAlt) != 0 {
r = append(r, byte(hid.GetMappingFromName("ALT_LEFT").Usb))
} else {
r = append(r, 0)
}
return r
}
func (s *swapInt) Differ(s2 *swapInt) []byte {
r := make([]byte, 0)
if !s2.contains(s.K1) {
r = append(r, s.K1)
}
if !s2.contains(s.K2) {
r = append(r, s.K2)
}
if !s2.contains(s.K3) {
r = append(r, s.K3)
}
if !s2.contains(s.K4) {
r = append(r, s.K4)
}
if !s2.contains(s.K5) {
r = append(r, s.K5)
}
if !s2.contains(s.K6) {
r = append(r, s.K6)
}
if !s2.contains(s.K7) {
r = append(r, s.K7)
}
if !s2.contains(s.K8) {
r = append(r, s.K8)
}
if !s2.contains(s.K9) {
r = append(r, s.K9)
}
return r
}
//OrbLoop Main loop for this device
func OrbLoop(km *morb.KeyMaps, KeyBus chan *keyevents.KeyEvent) {
eventcodes = morb.BINDING[:]
for i := 0; i < len(eventcodes); i++ {
ecm[uint16(eventcodes[i])] = i
}
fmt.Println("Windows Loop Init")
ctx := gousb.NewContext()
dev, err := ctx.OpenDeviceWithVIDPID(vendor, prod)
if err != nil {
panic(err)
}
fmt.Println("Device connected")
defer dev.Close()
conf, err := dev.Config(1)
if err != nil {
panic(err)
}
intf, err := conf.Interface(0, 0)
if err != nil {
panic(err)
}
fmt.Println("Windows Loop Interf")
defer intf.Close()
in, err := intf.InEndpoint(1)
if err != nil {
panic(err)
}
fmt.Println("Windows Loop Pointed")
data := make([]byte, in.Desc.MaxPacketSize)
rs, _ := in.NewStream(in.Desc.MaxPacketSize, 3)
swaper := new(swaps)
swaper.S1 = new(swapInt)
swaper.S2 = new(swapInt)
fmt.Println("Windows Loop Starting")
for {
_, err := rs.Read(data)
if err != nil {
panic(err)
}
addin := trans(data[0])
tdat := data[2:]
dat := append(addin, tdat...)
for i := 0; i < len(dat); i++ {
if dat[i] != 0 {
dat[i] = byte(hid.GetLinuxFromHid(uint16(dat[i])))
dat[i] = byte(km.Maps[km.Currentmap].Keymap[ecm[uint16(dat[i])]])
dat[i] = byte(hid.GetHidFromLinux(uint16(dat[i])))
dat[i] = byte(hid.GetWindowsFromHid(uint16(dat[i])))
}
}
err = binary.Read(bytes.NewReader(dat), binary.LittleEndian, swaper.S1)
if err != nil {
panic(err)
}
for _, pre := range swaper.S1.Differ(swaper.S2) {
if pre != 0 {
KeyEv := &keyevents.KeyEvent{}
KeyEv.Code = uint16(pre)
KeyEv.Type = 1
KeyBus <- KeyEv
}
}
for _, rel := range swaper.S2.Differ(swaper.S1) {
if rel != 0 {
KeyEv := &keyevents.KeyEvent{}
KeyEv.Code = uint16(rel)
KeyEv.Type = 2
KeyBus <- KeyEv
}
}
swaper.swap()
}
}
// +build windows
package orbweaver
import (
"bytes"
"encoding/binary"
"fmt"
morb "github.com/OrbTools/OrbCommon/devices/orbweaver"
"github.com/OrbTools/OrbCommon/hid"
"github.com/OrbTools/OrbMap/keyevents"
"github.com/google/gousb"
)
const (
vendor = gousb.ID(0x1532)
prod = gousb.ID(0x0207)
leftControl byte = 0x1
leftShift byte = 0x2
leftAlt byte = 0x4
)
type swaps struct {
S1 *swapInt
S2 *swapInt
}
type swapInt struct {
K1 byte
K2 byte
K3 byte
K4 byte
K5 byte
K6 byte
K7 byte
K8 byte
K9 byte
}
func (s *swapInt) contains(k byte) bool {
return (s.K1 == k || s.K2 == k || s.K3 == k || s.K4 == k || s.K5 == k || s.K6 == k || s.K7 == k || s.K8 == k || s.K9 == k)
}
func (s *swaps) swap() {
ss := s.S1
s.S1 = s.S2
s.S2 = ss
}
func trans(M byte) []byte {
r := make([]byte, 0)
if (M & leftShift) != 0 {
r = append(r, byte(hid.GetMappingFromName("SHIFT_LEFT").Usb))
} else {
r = append(r, 0)
}
if (M & leftControl) != 0 {
r = append(r, byte(hid.GetMappingFromName("CONTROL_LEFT").Usb))
} else {
r = append(r, 0)
}
if (M & leftAlt) != 0 {
r = append(r, byte(hid.GetMappingFromName("ALT_LEFT").Usb))
} else {
r = append(r, 0)
}
return r
}
func (s *swapInt) Differ(s2 *swapInt) []byte {
r := make([]byte, 0)
if !s2.contains(s.K1) {
r = append(r, s.K1)
}
if !s2.contains(s.K2) {
r = append(r, s.K2)
}
if !s2.contains(s.K3) {
r = append(r, s.K3)
}
if !s2.contains(s.K4) {
r = append(r, s.K4)
}
if !s2.contains(s.K5) {
r = append(r, s.K5)
}
if !s2.contains(s.K6) {
r = append(r, s.K6)
}
if !s2.contains(s.K7) {
r = append(r, s.K7)
}
if !s2.contains(s.K8) {
r = append(r, s.K8)
}
if !s2.contains(s.K9) {
r = append(r, s.K9)
}
return r
}
//OrbLoop Main loop for this device
func OrbLoop(km *morb.KeyMaps, KeyBus chan *keyevents.KeyEvent) {
eventcodes = morb.BINDING[:]
for i := 0; i < len(eventcodes); i++ {
ecm[uint16(eventcodes[i])] = i
}
fmt.Println("Windows Loop Init")
ctx := gousb.NewContext()
dev, err := ctx.OpenDeviceWithVIDPID(vendor, prod)
if err != nil {
panic(err)
}
fmt.Println("Device connected")
defer dev.Close()
conf, err := dev.Config(1)
if err != nil {
panic(err)
}
intf, err := conf.Interface(0, 0)
if err != nil {
panic(err)
}
fmt.Println("Windows Loop Interf")
defer intf.Close()
in, err := intf.InEndpoint(1)
if err != nil {
panic(err)
}
fmt.Println("Windows Loop Pointed")
data := make([]byte, in.Desc.MaxPacketSize)
rs, _ := in.NewStream(in.Desc.MaxPacketSize, 3)
swaper := new(swaps)
swaper.S1 = new(swapInt)
swaper.S2 = new(swapInt)
fmt.Println("Windows Loop Starting")
for {
_, err := rs.Read(data)
if err != nil {
panic(err)
}
addin := trans(data[0])
tdat := data[2:]
dat := append(addin, tdat...)
for i := 0; i < len(dat); i++ {
if dat[i] != 0 {
dat[i] = byte(hid.GetLinuxFromHid(uint16(dat[i])))
dat[i] = byte(km.Maps[km.Currentmap].Keymap[ecm[uint16(dat[i])]])
dat[i] = byte(hid.GetHidFromLinux(uint16(dat[i])))
dat[i] = byte(hid.GetWindowsFromHid(uint16(dat[i])))
}
}
err = binary.Read(bytes.NewReader(dat), binary.LittleEndian, swaper.S1)
if err != nil {
panic(err)
}
for _, pre := range swaper.S1.Differ(swaper.S2) {
if pre != 0 {
KeyEv := &keyevents.KeyEvent{}
KeyEv.Code = uint16(pre)
KeyEv.Type = 1
KeyBus <- KeyEv
}
}
for _, rel := range swaper.S2.Differ(swaper.S1) {
if rel != 0 {
KeyEv := &keyevents.KeyEvent{}
KeyEv.Code = uint16(rel)
KeyEv.Type = 2
KeyBus <- KeyEv
}
}
swaper.swap()
}
}

View File

@ -1,32 +1,32 @@
// +build linux !windows
package emu
import (
"github.com/OrbTools/OrbMap/keyevents"
"github.com/bendahl/uinput"
)
var vkm uinput.Keyboard = nil
//ProcKey keyboard emulator loop
func ProcKey(kb chan *keyevents.KeyEvent) {
println("Emu Unix Starting")
var err error
vkm, err = uinput.CreateKeyboard("/dev/uinput", []byte("Orbmap"))
if err != nil {
panic(err)
}
defer vkm.Close()
for {
KeyEv := <-kb
if KeyEv.Type == 1 {
if KeyEv.Value == 1 {
vkm.KeyDown(int(KeyEv.Code))
} else if KeyEv.Value == 2 {
} else {
vkm.KeyUp(int(KeyEv.Code))
}
}
}
}
// +build linux !windows
package emu
import (
"github.com/OrbTools/OrbMap/keyevents"
"github.com/bendahl/uinput"
)
var vkm uinput.Keyboard = nil
//ProcKey keyboard emulator loop
func ProcKey(kb chan *keyevents.KeyEvent) {
println("Emu Unix Starting")
var err error
vkm, err = uinput.CreateKeyboard("/dev/uinput", []byte("Orbmap"))
if err != nil {
panic(err)
}
defer vkm.Close()
for {
KeyEv := <-kb
if KeyEv.Type == 1 {
if KeyEv.Value == 1 {
vkm.KeyDown(int(KeyEv.Code))
} else if KeyEv.Value == 2 {
} else {
vkm.KeyUp(int(KeyEv.Code))
}
}
}
}

View File

@ -1,52 +1,52 @@
// +build windows
package emu
import (
"unsafe"
"github.com/OrbTools/OrbMap/keyevents"
"github.com/lxn/win"
)
func downKey(key uint16) {
in := []win.KEYBD_INPUT{
{
Type: win.INPUT_KEYBOARD,
Ki: win.KEYBDINPUT{
DwExtraInfo: 0,
WScan: key,
DwFlags: win.KEYEVENTF_SCANCODE,
Time: 0,
},
},
}
win.SendInput(1, unsafe.Pointer(&in[0]), int32(unsafe.Sizeof(in[0])))
}
func upKey(key uint16) {
in := []win.KEYBD_INPUT{
{
Type: win.INPUT_KEYBOARD,
Ki: win.KEYBDINPUT{
DwExtraInfo: 0,
WScan: key,
DwFlags: win.KEYEVENTF_KEYUP | win.KEYEVENTF_SCANCODE,
Time: 0,
},
},
}
win.SendInput(1, unsafe.Pointer(&in[0]), int32(unsafe.Sizeof(in[0])))
}
//ProcKey Windows support is so weird
func ProcKey(kb chan *keyevents.KeyEvent) {
println("Emu Windows Starting")
for {
KeyEv := <-kb
if KeyEv.Type == 1 {
downKey(KeyEv.Code)
} else if KeyEv.Type == 2 {
upKey(KeyEv.Code)
}
}
}
// +build windows
package emu
import (
"unsafe"
"github.com/OrbTools/OrbMap/keyevents"
"github.com/lxn/win"
)
func downKey(key uint16) {
in := []win.KEYBD_INPUT{
{
Type: win.INPUT_KEYBOARD,
Ki: win.KEYBDINPUT{
DwExtraInfo: 0,
WScan: key,
DwFlags: win.KEYEVENTF_SCANCODE,
Time: 0,
},
},
}
win.SendInput(1, unsafe.Pointer(&in[0]), int32(unsafe.Sizeof(in[0])))
}
func upKey(key uint16) {
in := []win.KEYBD_INPUT{
{
Type: win.INPUT_KEYBOARD,
Ki: win.KEYBDINPUT{
DwExtraInfo: 0,
WScan: key,
DwFlags: win.KEYEVENTF_KEYUP | win.KEYEVENTF_SCANCODE,
Time: 0,
},
},
}
win.SendInput(1, unsafe.Pointer(&in[0]), int32(unsafe.Sizeof(in[0])))
}
//ProcKey Windows support is so weird
func ProcKey(kb chan *keyevents.KeyEvent) {
println("Emu Windows Starting")
for {
KeyEv := <-kb
if KeyEv.Type == 1 {
downKey(KeyEv.Code)
} else if KeyEv.Type == 2 {
upKey(KeyEv.Code)
}
}
}

View File

@ -1,11 +1,11 @@
package keyevents
import "syscall"
//KeyEvent represents a keyevent
type KeyEvent struct {
Time syscall.Timeval
Type uint16
Code uint16
Value int32
}
package keyevents
import "syscall"
//KeyEvent represents a keyevent
type KeyEvent struct {
Time syscall.Timeval
Type uint16
Code uint16
Value int32
}

38
main.go
View File

@ -1,19 +1,19 @@
//generate:boxy
package main
import (
"flag"
"github.com/OrbTools/OrbMap/devices/orbweaver"
"github.com/OrbTools/OrbMap/emu"
"github.com/OrbTools/OrbMap/keyevents"
)
func main() {
orbs := flag.String("orbweaver", "", "Comma seperated string of orbs for the orbweaver")
flag.Parse()
KeyBus := make(chan *keyevents.KeyEvent, 128)
Maps := orbweaver.ProcOrbFiles(*orbs)
go orbweaver.OrbLoop(Maps, KeyBus)
emu.ProcKey(KeyBus)
}
//generate:boxy
package main
import (
"flag"
"github.com/OrbTools/OrbMap/devices/orbweaver"
"github.com/OrbTools/OrbMap/emu"
"github.com/OrbTools/OrbMap/keyevents"
)
func main() {
orbs := flag.String("orbweaver", "", "Comma seperated string of orbs for the orbweaver")
flag.Parse()
KeyBus := make(chan *keyevents.KeyEvent, 128)
Maps := orbweaver.ProcOrbFiles(*orbs)
go orbweaver.OrbLoop(Maps, KeyBus)
emu.ProcKey(KeyBus)
}