hidproxy

package module
v0.0.0-...-0a3a762 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

README

go-hidproxy

Proxies Bluetooth keyboards and mouse as HID devices (eg. with Raspberry Zero Pi W)

Build

Requires libudev-dev package (sudo apt install libudev-dev).

Build with Go 1.20+:

go install github.com/rosmo/go-hidproxy/cmd/go-hidproxy@latest
sudo cp ~/go/bin/go-hidproxy /usr/bin/go-hidproxy

Or even with a more complete example:

wget https://go.dev/dl/go1.22.2.linux-arm64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.22.2.linux-arm64.tar.gz
export PATH=$PATH:/usr/local/go/bin
sudo apt-get install -y libudev-dev
go install github.com/rosmo/go-hidproxy/cmd/go-hidproxy@latest
sudo cp ~/go/bin/go-hidproxy /usr/bin/go-hidproxy
sudo go-hidproxy

Install

  • Build the binary
  • Copy binary to /usr/sbin/go-hidproxy
  • Install systemd unit file to /etc/systemd/system
  • Reload daemons: sudo systemctl daemon-reload
  • Enable hidproxy: sudo systemctl enable hidproxy
  • (Optionally) Start hidproxy: sudo systemctl start hidproxy

Raspberry Pi Zero W setup

I used a pretty standard Raspbian image:

Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

You'll need to setup /boot/config.txt with:

dtoverlay=dwc2

In /etc/modules you should have:

dwc2
libcomposite
evdev

Pair Bluetooth keyboard/mouse

One time pairing:

# sudo bluetoothctl
> discoverable on
> pairable on
> agent NoInputNoOutput
> default-agent
> scan on
> pair aa:bb:cc:dd:ee:ff
> connect aa:bb:cc:dd:ee:ff
> trust aa:bb:cc:dd:ee:ff
Tested with
  • TEX Shinobi keyboard / Trackpoint combo
  • Razer Deathadder V2 Pro
  • Microsoft Designer Compact Keyboard

Documentation

Index

Constants

View Source
const (
	RIGHT_META    = 1 << 7
	RIGHT_ALT     = 1 << 6
	RIGHT_SHIFT   = 1 << 5
	RIGHT_CONTROL = 1 << 4
	LEFT_META     = 1 << 3
	LEFT_ALT      = 1 << 2
	LEFT_SHIFT    = 1 << 1
	LEFT_CONTROL  = 1 << 0

	BUTTON_LEFT   = 1 << 0
	BUTTON_RIGHT  = 1 << 1
	BUTTON_MIDDLE = 1 << 2
)

Variables

View Source
var Scancodes = map[uint16]uint16{
	2:   30,
	3:   31,
	4:   32,
	5:   33,
	6:   34,
	7:   35,
	8:   36,
	9:   37,
	10:  38,
	11:  39,
	57:  44,
	14:  42,
	28:  40,
	1:   41,
	106: 79,
	105: 80,
	108: 81,
	103: 82,
	59:  58,
	60:  59,
	61:  60,
	62:  61,
	63:  62,
	64:  63,
	65:  64,
	66:  65,
	67:  66,
	68:  67,
	69:  68,
	70:  69,
	12:  45,
	13:  46,
	15:  43,
	26:  47,
	27:  48,
	39:  51,
	40:  52,
	51:  54,
	52:  55,
	53:  56,
	41:  50,
	43:  49,
	30:  4,
	48:  5,
	46:  6,
	32:  7,
	18:  8,
	33:  9,
	34:  10,
	35:  11,
	23:  12,
	36:  13,
	37:  14,
	38:  15,
	50:  16,
	49:  17,
	24:  18,
	25:  19,
	16:  20,
	19:  21,
	31:  22,
	20:  23,
	22:  24,
	47:  25,
	17:  26,
	45:  27,
	21:  28,
	44:  29,
	86:  49,
	104: 75,
	109: 78,
	102: 74,
	107: 77,
	110: 73,
	119: 72,

	99:  70,
	87:  68,
	88:  69,
	113: 127,
	114: 129,
	115: 128,
	58:  57,
	158: 122,
	159: 121,
	29:  224,
	125: 227,
	42:  225,
	56:  226,
	100: 230,
	127: 231,
	97:  228,
	54:  229,
	111: 76,
	164: 232,
	165: 234,
	163: 233,
}

Functions

func GetDisconnectedDevices

func GetDisconnectedDevices(adapterId string) ([]string, error)

func HandleKeyboard

func HandleKeyboard(output chan<- error, input chan<- InputMessage, close <-chan bool, rate uint, delay uint, dev evdev.InputDevice) error

func HandleMouse

func HandleMouse(output chan<- error, input chan<- InputMessage, close <-chan bool, dev evdev.InputDevice) error

func SendKeyboardReports

func SendKeyboardReports(input <-chan InputMessage) error

func SendMouseReports

func SendMouseReports(input <-chan InputMessage) error

func SetupUSBGadget

func SetupUSBGadget()

func Start

func Start(config Config)

Types

type Config

type Config struct {
	SetupHid      bool
	SetupMouse    bool
	SetupKeyboard bool
	MonitorUdev   bool
	AdapterId     string
	KbdRepeat     int
	KbdDelay      int
	LogLevel      log.Level
}

type InputDevice

type InputDevice struct {
	Device string
	Name   string
}

type InputMessage

type InputMessage struct {
	Message   []byte
	Timestamp time.Duration
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL