golang-evdev
golang-evdev copied to clipboard
Is golang-evdev a alternative to my use-case ?
Hi, As github does not allow to send any message to gvalkov, I try a issue to state my question to him
Its a question, if golang-evdev can be used in my use-case...
Currently I am using a USB-Device https://www.usbbutton.com/ to toggle the state of a software.
As the device can only output a pre-defined textsequence, like "send-signal.sh(enter)" I have to use the cli as a separate step to start a shellscript, that is sending a signal to my app (sudo pkill -USR1 MyApp). Then the app reacts to the signal by toggling its state.
Press USB-Button -> USB Device pastes text sequence to cli "send-signal.sh(enter)" -> cli execute shellscript -> Shellscript sends signal to software -> Software toggles state
As this is a quite complicated way to toggle the software status, and I was wondering if golang-evdev is able to do the trick also, even without using the cli.
Press USB-Button -> golang-evdev -> Software toggles state
As its a headless device, it would be great if I don't have to use cli in future as I do currently....
Thanks and best regards
Alex
One week passed without reaction...
Hello @AlexMcGopher,
I don't have this device, but I have a use case that could help you.
I have a barcode reader that is seen as a keyboard, but I don't want the "keyboard" behavior. So I intercept the keypress and catch the barcode read, so I can handle it myself.
In your case, I don't know how the device is seen by the system (probably a keyboard), so with this lib you can easily catch your keypress and do your own magic.
Here is an extract of the code I have :
devices, err := evdev.ListInputDevices()
// find the good device
device := devices[0]
// catch device events
device.Grab()
for {
evt, err := device.ReadOne()
switch evt.Type {
case evdev.EV_KEY:
// handle the event
}
}