SUMMARY : Working with different keyboard

From: Frederic Piard (frederic_piard@kangourou.erli.gsi.fr)
Date: Sat Sep 04 1993 - 03:08:59 CDT


Hello,
My first question :

>We've got about 50 SparcStations with different keyboards.
>Somme are type 5, somme are type 4, somme are qwerty, and some are azerty.
>The probleme is between type 4 and type 5.
>With type 4, the delete key is placed very conveniently on the keyboard
>(up-right), and we all use it to delete the last caracter.
>With type 5 keybord, this convenient place (up-right) is for the backspace
key, >but this key produce a "^H" and erase nothing (eg : in a OpenWindows3's
>shelltool).
>I want to map the keybord in this manner :
> - If my keyboard is a type 4 so the delete key erase the last caracter.
> - If my keyboard is a type 5 so the backspace key erase the last caracter.
>
>I know how to remap a caracter (stty erase ^H), but I don't know how to check
>the keybord type.
>An other solution is to remap both the backspace key and the erase key for
>erasing the last caracter without checking the keyboard, but I don't know how
>to do this.
>
>Many thanks for all your help.

I've got the answer(s).
Thanks to :
Martin Kelly (dsnmkey@guinness.ericsson.se)
Mark Anderson (manderso@mitre.org)
Neal (nrd@lenti.med.umn.edu)
Joel Shandelman (shandelm@jpmorgan.com)
Kai Grossjohann (grossjoh@ls6.informatik.uni-dortmund.de)
Danny Johnson (danny@ews7.dseg.ti.com)
Nora Hermida (nhermida@sun1.wwb.noaa.gov)

There are a few solutions. One's working everytime (without any window manager,
with SunTools, OpenWindows and Motif) , other's working only with OpenWindows.
I prefere the first hand.

The first solutions test the keyboard :
````````````````````````````````````````````````````````````````````````````````
>From : Martin Kelly (dsnmkey@guinness.ericsson.se)
```````````````````
/*
 * FILE: kbinfo.c
 * AUTHOR: Martin Kelly DSN/D/N dsnmkey@guinness.ericsson.se
 * DESCR: Program to query a keyboard type on a Sun
 * DATE: 16-Feb-1993
 *
 * COPYRIGHT:
 *
 * VERSION: 1.0
 *
 * USAGE: kbinfo [-v]
 * returns the type (number) of the keyboard as defined
 * in the keytables.map file. These number directly correlate
 * with the files in the /usr/share/lib/keytables directory.
 * The verbose flag -v returns the full text name as specified
 * in that file.
 */

#include <ctype.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sundev/kbio.h>
#include <sundev/kbd.h>

#define TRUE 1

int kb;
int keyboard = 0;
int verbose_flag = 0;
char *progname;

char *kbd_layout[ ] = {
"US4", "US4", "FranceBelg4", "Canada4", "Denmark4", "Germany4", "Italy4",
"Netherland4", "Norway4", "Portugal4", "SpainLatAm4", "SwedenFin4",
"Switzer_Fr4", "Switzer_Ge4", "UK4", "", "Korea4", "Taiwan4",
"", "US101A_PC", "", "", "", "", "", "", "", "", "", "", "", "",
"Japan4", "US5", "US_UNIX5", "France5", "Denmark5", "Germany5", "Italy5",
"Netherland5", "Norway5", "Portugal5", "Spain5", "Sweden5", "Switzer_Fr5",
"Switzer_Ge5", "UK5", "Korea5", "Taiwan5", "Japan5", "", "",
"", "", "", "", "", "", "", "" };

main(argc,argv)
int argc;
char **argv;
{
        progname = *argv;

        while (argc > 1)
        {
                ++argv;
                --argc;

                switch (*(++*argv))
                {
                case 'v':
                        verbose_flag = TRUE;
                        break;
                case 'h':
                        fprintf(stdout,"%s: not very helpful\n",progname);
                        exit(0);
                        break;
                case 'V':
                        version();
                        break;
                default:
                        usage();
                        break;
                }
        }
        read_kbd();
        exit(0);
}

int read_kbd()
{
        if ((kb = open("/dev/kbd", O_RDONLY)) < 0)
        {
                fprintf(stderr,"%s: couldn't open keyboard\n",progname);
                exit(-1);
        }

        if (ioctl(kb, KIOCLAYOUT, &keyboard) < 0)
        {
                fprintf(stderr,"%s: couldn't get keyboard layout\n",progname);
                exit(-1);
        }
        else
                if (verbose_flag)
                        printf("%s\n",(keyboard < 60) ? kbd_layout[keyboard] :
"unknown" );
                else
                        printf("%d\n",keyboard);
        return;
}

int usage()
{
        fprintf(stderr,"Usage: %s [-v] \n",progname);
        exit(0);
}

int version()
{
        fprintf(stdout,"%s: Version 1.0 Release 1\n", progname);
        exit(0);
}

````````````````````````````````````````````````````````````````````````````````
>From : Joel Shandelman (shandelm@jpmorgan.com)
```````````
/*
 * kbdtype - utility to print out string identifying Sun keyboard type
 *
 * This program can be used to determine the type and layout of any
 * keyboard connected to a Sun system. The information can be useful
 * for setting up keyboard mappings and selecting X Window System
 * application defaults.
 *
 * Copyright 1993 by the ASK/Ingres Corporation.
 *
 * Author: Mike Glendinning, Ingres UK.
 */

#include <stdio.h>
#include <string.h>
#include <sys/fcntl.h>
#include <sundev/kbd.h>
#include <sundev/kbio.h>

char *programname;

usage ()
{
    fprintf (stderr, "Usage: %s [-brief][-kbd device]\n",
             programname);
    exit (1);
}

main (argc, argv)
    int argc;
    char *argv[];
{
    int brief = 0;
    char *kbddevice = "/dev/kbd";
    int kbdfd;
    int kbdtype, kbdlayout;
    char *kbdstr = "";
    char unknownstr[60];
    int i;
    char *cp;

    programname = argv[0];
    cp = strrchr (programname, '/');
    if (cp != NULL)
        programname = cp+1;

    for (i = 1; i < argc; i++) {
        char *arg = argv[i];
        int arglen = strlen (arg);

        if (arg[0] == '-') {
            if ((arg[1] == 'b') && !strncmp (arg, "-brief", arglen))
                brief = 1;
            else if ((arg[1] == 'k') && !strncmp (arg, "-kbd", arglen)) {
                if (++i >= argc) usage ();
                kbddevice = argv[i];
            } else
                usage ();
        } else
          usage ();
    }

    if ((kbdfd = open (kbddevice, O_RDONLY)) < 0) {
        fprintf (stderr, "%s: couldn't open '%s': ", programname, kbddevice);
        perror (NULL);
        exit (1);
    }

    if (ioctl (kbdfd, KIOCTYPE, &kbdtype) < 0) {
        fprintf (stderr, "%s: unable to get keyboard type: ", programname);
        perror (NULL);
        close (kbdfd);
        exit (1);
    }

    /*
     * I'm not sure how many of these values for 'kbdtype' can actually
     * occur. This is the complete list from '/usr/include/sundev/kbd.h'.
     * Any redundant values will not do too much harm, however.
     */
    switch (kbdtype) {
        case KB_KLUNK: /* Micro Switch 103SD32-2 */
            kbdstr = (brief ? "klunk" : " Micro Switch 103SD32-2.");
            break;
        case KB_VT100: /* Keytronics VT100 compatible */
            kbdstr = (brief ? "vt100" : " Keytronics VT100 compatible.");
            break;
        case KB_SUN2: /* Sun-2 custom keyboard */
            kbdstr = (brief ? "sun2" : " Type-2 Sun keyboard.");
            break;
        case KB_SUN3: /* Type 3 Sun keyboard */
            kbdstr = (brief ? "sun3" : " Type-3 Sun keyboard.");
            break;
        case KB_SUN4: /* Type 4 Sun keyboard */
            if (ioctl (kbdfd, KIOCLAYOUT, &kbdlayout) < 0) {
                fprintf (stderr, "%s: unable to get type 4 keyboard layout: ", programname);
                perror (NULL);
                close (kbdfd);
                exit (1);
            }
            switch (kbdlayout) {
                case 0x00: /* US4 */
                case 0x01: /* US4 */
                    kbdstr = (brief ? "US4" : " Type-4 U.S. keyboard.");
                    break;
                case 0x02: /* FranceBelg4 */
                    kbdstr = (brief ? "FranceBelg4" : " Type-4 French & Belgian keyboard.");
                    break;
                case 0x03: /* Canada4 */
                    kbdstr = (brief ? "Canada4" : " Type-4 Canadian keyboard.");
                    break;
                case 0x04: /* Denmark4 */
                    kbdstr = (brief ? "Denmark4" : " Type-4 Danish keyboard.");
                    break;
                case 0x05: /* Germany4 */
                    kbdstr = (brief ? "Germany4" : " Type-4 German keyboard.");
                    break;
                case 0x06: /* Italy4 */
                    kbdstr = (brief ? "Italy4" : " Type-4 Italian keyboard.");
                    break;
                case 0x07: /* Netherland4 */
                    kbdstr = (brief ? "Netherland4" : " Type-4 Dutch keyboard.");
                    break;
                case 0x08: /* Norway4 */
                    kbdstr = (brief ? "Norway4" : " Type-4 Norwegian keyboard.");
                    break;
                case 0x09: /* Portugal4 */
                    kbdstr = (brief ? "Portugal4" : " Type-4 Portuguese keyboard.");
                    break;
                case 0x0a: /* SpainLatAm4 */
                    kbdstr = (brief ? "SpainLatAm4" : " Type-4 Spanish & Latin American
keyboard.");
                    break;
                case 0x0b: /* SwedenFin4 */
                    kbdstr = (brief ? "SwedenFin4" : " Type-4 Swedish & Finnish keyboard.");
                    break;
                case 0x0c: /* Switzer_Fr4 */
                    kbdstr = (brief ? "Switzer_Fr4" : " Type-4 Swiss-French keyboard.");
                    break;
                case 0x0d: /* Switzer_Ge4 */
                    kbdstr = (brief ? "Switzer_Ge4" : " Type-4 Swiss-German keyboard.");
                    break;
                case 0x0e: /* UK4 */
                    kbdstr = (brief ? "UK4" : " Type-4 United Kingdom keyboard.");
                    break;
                case 0x10: /* Korea4 */
                    kbdstr = (brief ? "Korea4" : " Type-4 Korean keyboard.");
                    break;
                case 0x11: /* Taiwan4 */
                    kbdstr = (brief ? "Taiwan4" : " Type-4 Taiwanese keyboard.");
                    break;
                case 0x13: /* US101A_Sun */
                    kbdstr = (brief ? "US101A_Sun" : " Type-4 Sun U.S. 101A keyboard.");
                    break;
                case 0x20: /* Japan4 */
                    kbdstr = (brief ? "Japan4" : " Type-4 Japanese keyboard.");
                    break;
                case 0x21: /* US5 */
                    kbdstr = (brief ? "US5" : " Type-5 U.S. keyboard.");
                    break;
                case 0x22: /* US_UNIX5 */
                    kbdstr = (brief ? "US_UNIX5" : " Type-5 U.S. UNIX keyboard.");
                    break;
                case 0x23: /* France5 */
                    kbdstr = (brief ? "France5" : " Type-5 French keyboard.");
                    break;
                case 0x24: /* Denmark5 */
                    kbdstr = (brief ? "Denmark5" : " Type-5 Danish keyboard.");
                    break;
                case 0x25: /* Germany5 */
                    kbdstr = (brief ? "Germany5" : " Type-5 German keyboard.");
                    break;
                case 0x26: /* Italy5 */
                    kbdstr = (brief ? "Italy5" : " Type-5 Italian keyboard.");
                    break;
                case 0x27: /* Netherland5 */
                    kbdstr = (brief ? "Netherland5" : " Type-5 Dutch keyboard.");
                    break;
                case 0x28: /* Norway5 */
                    kbdstr = (brief ? "Norway5" : " Type-5 Norwegian keyboard.");
                    break;
                case 0x29: /* Portugal5 */
                    kbdstr = (brief ? "Portugal5" : " Type-5 Portuguese keyboard.");
                    break;
                case 0x2a: /* Spain5 */
                    kbdstr = (brief ? "Spain5" : " Type-5 Spanish keyboard.");
                    break;
                case 0x2b: /* Sweden5 */
                    kbdstr = (brief ? "Sweden5" : " Type-5 Swedish keyboard.");
                    break;
                case 0x2c: /* Switzer_Fr5 */
                    kbdstr = (brief ? "Switzer_Fr5" : " Type-5 Swiss-French keyboard.");
                    break;
                case 0x2d: /* Switzer_Ge5 */
                    kbdstr = (brief ? "Switzer_Ge5" : " Type-5 Swiss-German keyboard.");
                    break;
                case 0x2e: /* UK5 */
                    kbdstr = (brief ? "UK5" : " Type-5 United Kingdom keyboard.");
                    break;
                case 0x2f: /* Korea5 */
                    kbdstr = (brief ? "Korea5" : " Type-5 Korean keyboard.");
                    break;
                case 0x30: /* Taiwan5 */
                    kbdstr = (brief ? "Taiwan5" : " Type-5 Taiwanese keyboard.");
                    break;
                case 0x31: /* Japan5 */
                    kbdstr = (brief ? "Japan5" : " Type-5 Japanese keyboard.");
                    break;
                default:
                    if (brief)
                        kbdstr = "sun4";
                    else {
                        sprintf (unknownstr, " Type-4 Sun keyboard (layout %d).", kbdlayout);
                        kbdstr = unknownstr;
                    }
                    break;
            }
            break;
        case KB_VT220: /* Emulation vt220 */
            kbdstr = (brief ? "vt220" : " vt220 emulation.");
            break;
        case KB_VT220I: /* International vt220 Emulation */
            kbdstr = (brief ? "vt220i" : " vt220 emulation (international).");
            break;
        case KB_ASCII: /* Ascii terminal masquerading as kbd */
            kbdstr = (brief ? "ascii" : "n ASCII terminal.");
            break;
        default:
            if (brief)
                kbdstr = "unknown";
            else {
                sprintf (unknownstr, "n unknown keyboard type (%d).", kbdtype);
                kbdstr = unknownstr;
            }
            break;
    }

    if (!brief)
        printf ("Keyboard '%s' is a", kbddevice);
    printf ("%s\n", kbdstr);

    close (kbdfd);

    exit (0);
}

The second solutions remap the keybord without testing it :
````````````````````````````````````````````````````````````````````````````````
>From : Neal (nrd@lenti.med.umn.edu)
```````````
  In .xinitrc

    xmodmap -e "keysym BackSpace = Delete"

  In .Xdefaults

    XTerm*ttyModes: erase ^?

This maps the backspace key to be the delete key. This way they both
work. If I need to use ^H, I type it. I sometimes have to do this
when telneting or ftping to some sites. Rlogin passes this info.

````````````````````````````````````````````````````````````````````````````````
>From : Kai Grossjohann (grossjoh@ls6.informatik.uni-dortmund.de)
```````````````````````
Use xmodmap:

        xmodmap -e 'keycode 50=Delete'

On the Sun4 keyboard, this is the Backspace key, and after this
command the Backspace key behaves just like the Delete key. I think
this works for the Sun5 keyboard, too



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:08:09 CDT