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?