How to send a command when pressing a key

Dear lazy web,

How can I send a command when pressing a key? To make it more complex: I have two input devices A and B. The command should be only sent, when the keys of device A are pressed (and not device B). The devices A and B have the same key codes. For example, pressing the dot key on device A should run a command, but pressing the dot key on device B should just produce a dot. Is it possible to use device A as input device for lirc?

5 thoughts on “How to send a command when pressing a key

  1. If they have separate files in /dev maybe, the codes for A would only come out /dev/inputA, not /dev/inputB, so you could point lirc to only look for commands from /dev/inputA, so in theory yes, but I don’t use lirc, so I’m not sure.

  2. That strategy should work. I run a daemon that reads


    and executes configured commands when it detects certain shortcuts.
    I do it like this since I want to be able to do key signing and control remote controlled power sockets in a manner that makes it impossible to misuse them remotely if somebody only gets access to my normal u ser account and not root.

  3. In X you can load different keymaps for different devices (xinput list, then setxkbmap -device …). OTOH then you’d need to understand XKB, create a custom XKB option file and install it into the right place on the filesystem — all of which are sadly nontrivial.

    Maybe you could alternatively write an app that grabs a key on a specific input device only, assuming that XInput2 allows that. Also nontrivial.

  4. As well as the options above, you could use uinput to write a program that maps keycodes from that device into different keycodes on a synthetic device – something like the sort of thing that mouseemu does.

Comments are closed.