diff --git a/README.md b/README.md index d6426f1..e6c0891 100644 --- a/README.md +++ b/README.md @@ -44,11 +44,16 @@ The Shuttle acts as a mouse when you plug it into Ubuntu. Disable it with: "Mouse2" id=3 [XExtensionKeyboard] # Disable with: - $ xinput set-int-prop 2 "Device Enabled" 8 0 + $ xinput disable 2 Ref: https://unix.stackexchange.com/questions/91075/how-to-disable-keyboard +## Run + +With: + + sudo shuttle-go /dev/input/by-id/usb-Contour_Design_ShuttlePRO_v2-event-if00 TODO ---- diff --git a/main.go b/main.go index 1770f2b..0b30e6c 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,8 @@ func main() { os.Exit(10) } + go disableXInputPointer() + // X-window title change watcher watcher := NewWindowWatcher() if err := watcher.Setup(); err != nil { @@ -37,7 +39,7 @@ func main() { go watcher.Run() // Virtual keyboard - vk, err := uinput.CreateKeyboard("/dev/uinput", []byte("Shuttle Pro V2")) + vk, err := uinput.CreateKeyboard("/dev/uinput", []byte("Go Virtual Shuttle Pro V2")) if err != nil { log.Println("Can't open dev:", err) } diff --git a/xinput.go b/xinput.go new file mode 100644 index 0000000..b5fe248 --- /dev/null +++ b/xinput.go @@ -0,0 +1,40 @@ +package main + +import ( + "fmt" + "log" + "os/exec" + "regexp" + "time" +) + +var xinputDevices = []*regexp.Regexp{ + regexp.MustCompile(`↳ Contour Design ShuttlePRO v2\s+id=(\d)\s`), +} + +func disableXInputPointer() { + for { + cnt, err := exec.Command("xinput", "list").Output() + if err != nil { + log.Println("Couldn't list xinput:", err) + goto end + } + + for _, dev := range xinputDevices { + matches := dev.FindStringSubmatch(string(cnt)) + if matches == nil { + continue + } + + id := matches[1] + fmt.Println("Disabling XInput id:", id) + if err := exec.Command("xinput", "disable", id).Run(); err != nil { + log.Println("Couldn't disable xinput device:", err) + goto end + } + } + + end: + time.Sleep(60 * time.Second) + } +}