2020-08-20 14:57:57 +00:00
|
|
|
package keypressdetector
|
2020-08-17 13:50:39 +00:00
|
|
|
|
|
|
|
// #cgo CFLAGS: -g -Wall
|
|
|
|
// #include "evdev.h"
|
|
|
|
// #include <stdlib.h>
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-08-20 14:57:57 +00:00
|
|
|
// Evdev can detect keypresses on /dev/input devices
|
|
|
|
type Evdev struct {}
|
|
|
|
|
|
|
|
// BlockUntilKeypress waits until a key is pressed on the specified device
|
|
|
|
func (Evdev) BlockUntilKeypress(devicePath string) error {
|
2020-08-17 13:50:39 +00:00
|
|
|
path := C.CString(devicePath)
|
|
|
|
defer C.free(unsafe.Pointer(path))
|
|
|
|
|
|
|
|
ret := C.block_until_keypress(path)
|
|
|
|
if ret < 0 {
|
|
|
|
return syscall.Errno(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|