// Package evdev is the kernel input-event ABI. package evdev import ( "fmt" "os" "path/filepath" "unsafe" "golang.org/x/sys/unix" ) const ( Syn = 0x00 Key = 0x01 Abs = 0x03 SynReport = 0x00 BtnTouch = 0x14a AbsX = 0x00 AbsY = 0x01 propDirect = 0x01 EventSize = 24 ) func ioc(nr, size uintptr) uintptr { const iocRead = 2 return iocRead<<30 | size<<16 | 'E'<<8 | nr } type Touchscreen struct { F *os.File MinX, MaxX, MinY, MaxY int32 } // Picks the direct-input device that reports absolute X and Y, which is the // touchscreen; a mouse is relative and a keyboard has no absolute axes. func FindTouchscreen(flag int) (*Touchscreen, error) { paths, err := filepath.Glob("/dev/input/event*") if err != nil { return nil, err } for _, p := range paths { f, err := os.OpenFile(p, flag, 0) if err != nil { continue } var props, absBits uint64 if _, _, errno := unix.Syscall(unix.SYS_IOCTL, f.Fd(), ioc(0x09, 8), uintptr(unsafe.Pointer(&props))); errno != 0 { f.Close() continue } if _, _, errno := unix.Syscall(unix.SYS_IOCTL, f.Fd(), ioc(0x20+Abs, 8), uintptr(unsafe.Pointer(&absBits))); errno != 0 { f.Close() continue } if props&(1<