Bug 5036

Summary: showkey shows wrong raw scancodes
Product: Busybox Reporter: Steffen Daode Nurpmeso <sdaoden>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: enhancement CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description Steffen Daode Nurpmeso 2012-04-04 12:05:39 UTC
When i try out the code from the showkey applet in busybox it gives
me completely wrong scancodes.
The following code gives correct scancodes, but since i've never
read the kernel sources it may not get all cases correctly.
(It's from my own showkey.c that works on {Open,Free}BSD and Linux.
The "kernel sources" is still true though..)


static ssize_t
mode_keycode(unsigned char *buf, ssize_t len)
{
    unsigned char *cursor;

    for (cursor = buf; --len >= 0;) {
        unsigned int isplain = 1, kc = *cursor++, rc = kc, isdown;

        if ((rc & 0xF0) == 0xE0 || (rc & 0xF8) == 0xF0) {
            isplain = 0;
            if (--len < 0) {
                *buf = (unsigned char)rc;
                len = 1;
                break;
            }

            kc <<= 8;
            kc |= *cursor++;
            rc = kc;
            kc &= ((kc & 0xF000) == 0xE000) ? 0x0FFF : 0x00FF;
        }

        isdown = (0 == (kc & 0x80));
        kc &= ~0x0080;
        if (! isplain)
            kc |= 0x80;

        printf("keycode %3u %-7s (0x%04X: 0x%04X | %c)\r\n",
            kc, (isdown ? "press" : "release"),
            rc, kc, (isdown ? 'v' : '^'));
    }

    return ((len <= 0) ? 0 : len);
}
Comment 1 Steffen Daode Nurpmeso 2012-04-17 11:13:42 UTC
Hrmpf.
Ok.
Well it was so nice because FreeBSD and OpenBSD versions
are reproducably correct, and using the algorithm on Linux
just came up with the same keycodes that are correct for
the mentioned nicely documented OSs...
Since you've been silent i've prepared kbd-1.12 on TinyCore4.4
and indeed - ouch - dumpkeys(1) (and showkey(1)) agrees with you,
and throws me down into the hell of idiots.
My Linux error was that i've used _RAW not _MEDIUMRAW.
So *sorry for the noise*.
If i'll fail to close this ticket of shame, would anyone who
is capable to work with bug trackers do it for me, once in a while?
Thanks.