1

I a using lirc for python. This is working pretty good, but I miss one function: In my tests only a code was sent, when a button was pressed. Now, I want to print a code, while the key is pressed. In other words, a function should be started by "key down" and stopped by "key up". Using just the lirc.nextcode() is not working, because only the "key down" event is captured.

So, is there any trick to detect a "key up" with python?

vtni
  • 950
  • 3
  • 14
  • 43

3 Answers3

2

Actually, lircd has the --release option which generates synthetic release events, see the manpage at http://lirc.org/html/lircd.html

There is also the lircd-uinput add-on which feeds the kernel with the lirc keypress events. These events are made available on a /dev/input device, complete with repetition and release events. See the lircd-uinput manpage at http://lirc.org/html/lircd-uinput.html.

leamas
  • 151
  • 1
  • 6
1

There is no such feature in lirc. Think about it like this: a infrared signal from a remote is either received or not, there is no such thing as a keyup event, not even a keydown event.

You will have to code your own key up and key down events. Have a look at the way you can make configuration files, specifically the part about delay: http://www.lirc.org/html/configure.html Configure in such a way that many events are sent per second.

Then, put lirc in non-blocking mode (see https://github.com/tompreston/python-lirc). You can then loop over lirc.nextcode() and if it returns no event or returns an event for a different key, you have your key up event.

Munchhausen
  • 442
  • 4
  • 16
  • By using `mode2 -d /dev/lirc0` and pressing a button, I can see that signals are received continuously. I am not sure how the delay option of the lirc config can help me, because it just ignores some repeats. – vtni Aug 07 '16 at 22:33
0

You can check out my answer here: LIRC - How to use as keyboard command?

Basically, you can edit the lircd-uinput.service to add the release event for you. There may be a way to programmatically add the release event, but I don't know how to do that. Having the service do it is very responsive, and works well for my application.

sudo nano /lib/systemd/system/lircd-uinput.service

####find this line####
ExecStart=/usr/sbin/lircd-uinput 

####change to#########
ExecStart=/usr/sbin/lircd-uinput --add-release-events

#then reload/restart all the lircd services...
Ken H
  • 331
  • 2
  • 10