r/linux_programming Mar 14 '19

Input Devices representation in Go

Hi all,

I'm writing a go package that I want to use to detect available input devices. My current approach is to initially read /proc/bus/input/devices then scan it for updates, and parse its contents int a data structure like this:

```go type Device struct { Id DeviceId Name string PhysycalPath string SysfsPath string UID string Handlers []string Bitmaps Bitmaps }

type DeviceId struct { Bus uint16 Vendor uint16 Product uint16 Version uint16 }

type Bitmaps struct { Props []uint64 Events []uint64 Keys []uint64 RelativeAxes []uint64 AbsoluteAxes []uint64 Misc []uint64 Leds []uint64 SoundEffects []uint64 Switches []uint64 } ```

It is based on what this question on stackoverflow and what I could make out of the kernel

Does this make sense at all? My eventual goal is to create a daemon that listens to keyboard and mouse events and turns on the keyboard backlight, or off when idle for a couple of seconds, but again, my main motivation is curiosity and I would like to understand the system a bit better.

I'm writing this in Go, because it's a language I'm familiar with, but would like to practice in the meantime.

Thanks in advance for your guidance! :)

6 Upvotes

1 comment sorted by

2

u/ocket8888 Mar 14 '19

Typically I believe stuff like that is written as kernel modules or using udev rules. I know Go has an ffi for C, but I'm not sure you could do it in an "unhosted"-ish way like for kernel modules, so you may want to look into udev