LIRC - How to use as keyboard command?

守給你的承諾、 提交于 2021-02-07 10:29:58

问题


i have a question about LIRC in Debian. I searched now for some days and could not find any solution for my problem.

Is it possible to use an IR-Remote to send keyboard commads?

I will explain: I use the "read" function in a shell script. So i.e. i press the "T" key something happens. Now i want to send via LIRC the same "T" so that the shell script is working with the remote, too.

The other way is, not in a shell script but at my sources of the C-program. Here i use a code like this:

case 't': {

so if button "t" at keyboard is pressed something happens.

I hope someone can help me to use LIRC because i can´t understand the descriptions at the LIRC webpage. Every example is based on programs they allready support lirc commands.

Thank you very much Regards Thomas


回答1:


Assuming that you know how to use lircd, irexec and configure it through /etc/lircd.conf and /etc/lircrc, you could have something like this in your /etc/lircrc:

begin
        remote = name-of-your-remote
        prog   = irexec
        button = BTN_1
        config = echo T >/dev/xxx
end

BTN_1 should be configured in your /etc/lircd.conf to match 'T' key on your remote IR keyboard.

xxx is the TTY device that is used by your active shell, e.g. I've tried it with /dev/pts/0

If you need it to be accessible from your custom program's stdin, you can use the following config:

begin
        remote = name-of-your-remote
        prog   = irexec
        button = BTN_1
        config = echo T | your-prog
end



回答2:


I found that the lircd-uinput.service is used to send keyboard events to /dev/uinput, basically to the console. This is a handy service if you want to use a remote to send a keyboard key to a custom menu or program running on the console. The problem with the service, is that it keeps repeating the key until it receives a release code.

The 'repeat' behavior is by design, I guess because most well-written applications probably send something like a KEY_DOWN when a key is pressed, then a KEY_UP when it is released. But my simple application is not smart enough to send a release code, so I found an easy solution to the key repeat problem, and can use the service to fake a keyboard using an IR remote.

To make the lircd-uinput.service register the key-release event automatically, and stop repeating the key, edit the service and add the --add-release-events option.

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

Restart the services and make sure they're active.

sudo systemctl force-reload lircd
sudo systemctl force-reload lircd-uinput
sudo systemctl status lircd
sudo systemctl status lircd-uinput

#I had to start lircd-uinput, since force-reload didn't: 
sudo systemctl start lircd-uinput

Now the service only enters one keypress for each remote button press, and automatically sends the KEY_UP command. If you know how to send the KEY_UP commands in your application, that might work better than this solution.

To figure out the key commands that correspond to keyboard keys, you can list all possible keyboard events supported by the kernel by running:

irrecord -l

For example, if you want your remote to press the down arrow key on your console, the corresponding remote key is 'KEY_DOWN'. Then your remote file (/etc/lirc/lircd.conf.d/myremote.conf) would contain that key name.

begin remote

  name  myremote
 #<sniped...remote stuff here...>
      begin codes
 #    <sniped other codes>

          KEY_DOWN                 0x00FF

 #    <sniped other codes>
      end codes

end remote

Now that we've stopped the key repeating, this is a really useful service. It is much more responsive than using irexec to fake a keyboard key to the console, and you don't need any configuration in irexec.lircrc to send keystrokes to your console. And you can still use irexec for your other, non-keyboard related commands.



来源:https://stackoverflow.com/questions/19536799/lirc-how-to-use-as-keyboard-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!