uinput-controller: Format code

This commit is contained in:
Unrud 2023-02-23 01:09:29 +01:00
parent feaf02217c
commit 809d3a0064
2 changed files with 39 additions and 38 deletions

3
go.mod
View file

@ -3,9 +3,8 @@ module github.com/unrud/remote-touchpad
go 1.17 go 1.17
require ( require (
github.com/bendahl/uinput v1.6.0
github.com/godbus/dbus/v5 v5.1.0 github.com/godbus/dbus/v5 v5.1.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
golang.org/x/net v0.7.0 golang.org/x/net v0.7.0
) )
require github.com/bendahl/uinput v1.6.0 // indirect

View file

@ -21,10 +21,12 @@
package inputcontrol package inputcontrol
import "github.com/bendahl/uinput" import (
import "errors" "errors"
"github.com/bendahl/uinput"
)
var ukeysMap = map[Keysym]int { var ukeysMap = map[Keysym]int{
0x0061: uinput.KeyA, 0x0061: uinput.KeyA,
0x0062: uinput.KeyB, 0x0062: uinput.KeyB,
0x0063: uinput.KeyC, 0x0063: uinput.KeyC,
@ -63,35 +65,35 @@ var ukeysMap = map[Keysym]int {
0x0038: uinput.Key8, 0x0038: uinput.Key8,
0x0039: uinput.Key9, 0x0039: uinput.Key9,
0xff1b: uinput.KeyEsc, 0xff1b: uinput.KeyEsc,
0x002d: uinput.KeyMinus, 0x002d: uinput.KeyMinus,
0x002b: uinput.KeyKpplus, 0x002b: uinput.KeyKpplus,
0x002a: uinput.KeyKpasterisk, 0x002a: uinput.KeyKpasterisk,
0x003d: uinput.KeyEqual, 0x003d: uinput.KeyEqual,
0xff08: uinput.KeyBackspace, 0xff08: uinput.KeyBackspace,
0xff09: uinput.KeyTab, 0xff09: uinput.KeyTab,
0x0028: uinput.KeyLeftbrace, 0x0028: uinput.KeyLeftbrace,
0x0029: uinput.KeyRightbrace, 0x0029: uinput.KeyRightbrace,
0xff0d: uinput.KeyEnter, 0xff0d: uinput.KeyEnter,
0x003b: uinput.KeySemicolon, 0x003b: uinput.KeySemicolon,
0x0027: uinput.KeyApostrophe, 0x0027: uinput.KeyApostrophe,
0x0060: uinput.KeyGrave, 0x0060: uinput.KeyGrave,
0x005c: uinput.KeyBackslash, 0x005c: uinput.KeyBackslash,
0x002c: uinput.KeyComma, 0x002c: uinput.KeyComma,
0x0abd: uinput.KeyDot, 0x0abd: uinput.KeyDot,
0x002f: uinput.KeySlash, 0x002f: uinput.KeySlash,
0x0020: uinput.KeySpace, 0x0020: uinput.KeySpace,
0xff50: uinput.KeyHome, 0xff50: uinput.KeyHome,
0xff52: uinput.KeyUp, 0xff52: uinput.KeyUp,
0xff51: uinput.KeyLeft, 0xff51: uinput.KeyLeft,
0xff53: uinput.KeyRight, 0xff53: uinput.KeyRight,
0xff57: uinput.KeyEnd, 0xff57: uinput.KeyEnd,
0xff54: uinput.KeyDown, 0xff54: uinput.KeyDown,
0xffff: uinput.KeyDelete, 0xffff: uinput.KeyDelete,
0x1008FF12: uinput.KeyMute, 0x1008FF12: uinput.KeyMute,
0x1008FF11: uinput.KeyVolumedown, 0x1008FF11: uinput.KeyVolumedown,
0x1008FF13: uinput.KeyVolumeup, 0x1008FF13: uinput.KeyVolumeup,
0xffeb: uinput.KeyLeftmeta, 0xffeb: uinput.KeyLeftmeta,
0x1008ff26: uinput.KeyBack, 0x1008ff26: uinput.KeyBack,
0x1008ff27: uinput.KeyForward, 0x1008ff27: uinput.KeyForward,
0x1008ff17: uinput.KeyNextsong, 0x1008ff17: uinput.KeyNextsong,
@ -101,7 +103,7 @@ var ukeysMap = map[Keysym]int {
type uinputController struct { type uinputController struct {
keyboard uinput.Keyboard keyboard uinput.Keyboard
mouse uinput.Mouse mouse uinput.Mouse
} }
func init() { func init() {
@ -131,7 +133,7 @@ func (p *uinputController) Close() error {
func (p *uinputController) sendKeysym(sym Keysym) error { func (p *uinputController) sendKeysym(sym Keysym) error {
if sym >= 0x0041 && sym <= 0x005a { // capital letters if sym >= 0x0041 && sym <= 0x005a { // capital letters
p.keyboard.KeyDown(uinput.KeyLeftshift) p.keyboard.KeyDown(uinput.KeyLeftshift)
p.keyboard.KeyPress(ukeysMap[sym + 0x20]) p.keyboard.KeyPress(ukeysMap[sym+0x20])
p.keyboard.KeyUp(uinput.KeyLeftshift) p.keyboard.KeyUp(uinput.KeyLeftshift)
} else if key, ok := ukeysMap[sym]; ok { } else if key, ok := ukeysMap[sym]; ok {
p.keyboard.KeyPress(key) p.keyboard.KeyPress(key)
@ -145,7 +147,7 @@ func (p *uinputController) KeyboardText(text string) error {
if err != nil { if err != nil {
return err return err
} }
err = p.sendKeysym(keysym); err = p.sendKeysym(keysym)
} }
return nil return nil
@ -161,25 +163,25 @@ func (p *uinputController) KeyboardKey(key Key) error {
func (p *uinputController) PointerButton(button PointerButton, press bool) error { func (p *uinputController) PointerButton(button PointerButton, press bool) error {
switch button { switch button {
case PointerButtonLeft: case PointerButtonLeft:
if press { if press {
p.mouse.LeftPress() p.mouse.LeftPress()
} else { } else {
p.mouse.LeftRelease() p.mouse.LeftRelease()
} }
case PointerButtonRight: case PointerButtonRight:
if press { if press {
p.mouse.RightPress() p.mouse.RightPress()
} else { } else {
p.mouse.RightRelease() p.mouse.RightRelease()
} }
case PointerButtonMiddle: case PointerButtonMiddle:
if press { if press {
p.mouse.MiddlePress() p.mouse.MiddlePress()
} else { } else {
p.mouse.MiddleRelease() p.mouse.MiddleRelease()
} }
default: default:
return errors.New("unsupported pointer button") return errors.New("unsupported pointer button")
} }
return nil return nil