lirc_keybd -- simplified
Believe the above title and you're ready to ..., whatever. lirc_keybd
really is quite simple, it reads strings from /dev/lircd, decides if
it is a normal or modifier key, the responds accordingly. If it is
a normal key, it is immediately strobed into /dev/uinput as a KEYDOWN
+ KEYUP sequence. Modifier keys are immediately passed into /dev/uinput
as a KEYDOWN, but the KEYUP is not sent until the key is really released.
Modifier keys may be release by "hearing" a "BRK_" string for that key
or a "ALL_UP" is heard.
IR keycodes are translated into system keycodes via the table
appropriate to the keyboard that is being used. If the sources were
compiled for WebPal, then the keycode translation table would be found
in "CodesToKeys_webpal.h". The modifier actions are defined in
"CodesToMod_webpal.h". The process is that when a keystring is
received, it is qualified as to the name of the remote control, if
the name of the remote control is not "WebPal_Keyboard", then the
string is ignored.
When a string from the WebPal_Keyboard is heard, we sscanf the
keycode from the long string of numeric chars, and get the keycode
that the IR keyboard sent. That keycode is than compared first against
the CodesToMod_webpal table to see if it is a special key (alt, shift,
etc.). If it is a special modifier key, then flags are set, and the
KEYDOWN is sent to uinput for that system keycode. If it is not a
special key, then the system keycode is then strobe into uinput with
a KEYDOWN KEYUP sequence. Essentially, we ignore the "BRK_" code
for normal keys, modifiers are another matter (read the code).
TopKeyboard repeat
One of the problems I ran into was that the keyboard will send
repeating keys when you hold, or press, a key for too long a time.
It was very easy to type things in and get double entries on keys,
but I did want to keep the auto-repeat feature. The solution was
to implement a small delay inside lirc_keybd to "hesitate" entering
the same keyvalue as before. If any "BRK_" is heard, it will reset
the timer, or if the keycode changes, it will also reset the hesitation
timer. This logic is a bit touchy to implement but it works fairly
well for my typing prowess (speed). If you type slower than I, and
you keep getting multiple keys, try adjusting the "AutoDelay10MS"
value. It should help.
TopRemapping keys
The keys on the WebPal keyboard have been all mapped into corresponding
system keycodes. However, you may wish to use irxevent to run some
program if a selected key is pressed on the IR keyboard, but you run
into a problem where lirc_keybd is also entering a key into the system
keyboard queue. To stop lirc_keybd from effectively recognizing that
key, run lirc_keybd in DEBUG mode, note the keycode value, then enter
a ZERO (0) into the CodesToKeys table at that index location. Seeing
a NULL keycode will cause lirc_keybd to drop that key.
Likewise, if you wish to change a code, move a key, do the same.
Run DEBUG mode, note the keycode from lircd, then replace the current
CodesToKeys entry with your new system keycode. Look at
/usr/include/linux/input.h for a list of valid (recognized) system
keycodes. I've done this to change the "POWER" button to "ESC".
WARNING! One mistake that I made when mapping out the Shannon keyboard
was to forget to make an appropriate entry into the CodesToMod table.
I had the correct keycode in CodesToKeys, but CodesToMod had nothing
on that keycode as a modifier key. The result was that I'd press that
key and it wouldn't behave as it should. This problem is only with the
modifier keys, normal keys don't have entries in CodesToMod.