Robert Krten <rk@parse.com> wrote:
Is there a way to force caps lock off FOREVER ? We have a barcode
scanner connected via the keyboard port, and if the user turns on
CAPS LOCK our barcodes show up in inverse case… Any solutions?
We’re using 6.2.1 x86
Solved, with the help of Jon Wyatt.
Basically, what I do is simply look at the caps lock key after our
barcode scanner delivers the completed barcode. Because the barcode
scanner operates very fast, there is only a tiny window after we get
the last character and before we check the caps lock status where things
could go wrong – and this would have to be done by a particularly
fast operator who was toggling the caps lock as they were scanning
barcodes; not likely in our application.
So, here’s the magic code:
static int devkbd; // file descriptor for /dev/kbd
void init (void)
{
…
// set up a file descriptor for the raw keyboard device
if ((devkbd = open ("/dev/kbd", O_RDONLY)) == -1) {
sl_printf ("%s %d: can’t open /dev/kbd for O_RDONLY (errno %d, %s); CAPS LOCK detect feature disabled!\n", FILE, LINE, errno, strerror (errno));
}
}
void process_barcode (char *buffer)
{
…
if (devkbd != -1) {
invert = 0; // by default, don’t toggle the case of characters from the barcode scanner
if (sts = devctl (devkbd, DCMD_CHR_LINESTATUS, &i, sizeof (i), NULL)) {
sl_printf ("%s %d: can’t devctl (DCMD_CHR_LINESTATUS) retval %d (%s)\n", FILE, LINE, sts, strerror (sts));
} else {
invert = !!(i & _LINESTATUS_CON_CAPS); // snap status (we’re assuming caps lock is still in the same state as when the barcode scan began)
}
if (invert) {
for (p = buffer; *p; p++) {
if (isalpha (*p)) {
if (isupper (*p)) {
*p = tolower (*p);
} else {
*p = toupper (*p);
}
}
}
}
}
…
}
Cheers,
-RK
–
[If replying via email, you’ll need to click on the URL that’s emailed to you
afterwards to forward the email to me – spam filters and all that]
Robert Krten, PDP minicomputer collector http://www.parse.com/~museum/