This is a summary posting !
---------------------------------------------------------------------------
Original Question:
In comp.sys.sun.hardware you write:
>Does anyone know of a way to determine the difference
>between a sun type 4 keyboard, and the new type 5 ones.
>(or even between the two type 5 versions).
>The ioctl(KIOCTYPE) call always returns type4 for
>all of the above versions.
---------------------------------------------------------------------------
Short and Sweet Answer:
> From: terai@mink.nri.co.jp (TERAI Kojun)
Following code segment can be used.
------ cut here -----
#include <stdio.h>
#include <fcntl.h>
#include <sundev/kbio.h>
#include <sys/ioctl.h>
void main()
{
int fd, type,type2;
fd = open("/dev/kbd", O_RDWR, 0);
ioctl(fd, KIOCTYPE, &type);
ioctl(fd, KIOCLAYOUT, &type2);
printf("KIOCTYPE = %d\n",type);
printf("KIOCLAYOUT = %d\n",type2);
if( type2 == 32 ){
fprintf(stdout,"type4\n");
}else if( type2 == 49){
fprintf(stdout,"type5\n");
}else{
fprintf(stdout,"Error\n");
}
}
-------------------------------------------------------------------
Everything You Always Wanted To Know,
But Were Afraid To Ask !
> From: khaw@parcplace.com (Mike Khaw)
You have to distinguish type 4 from type 5 by layout:
--- CUT HERE ---
/* tested on SunOS 4.1.3. Don't know about Solaris 2.x */
#include <stdio.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sundev/kbio.h>
#include <sundev/kbd.h>
static char *kbdname[] =
{
"Micro Switch 103SD32-2", /* KB_KLUNK == 0x00 [0] */
"Keytronics VT100 clone", /* KB_VT100 == 0x01 */
"Sun type 2", /* KB_SUN2 == 0x02 */
"Sun type 3", /* KB_SUN3 == 0x03 */
"Sun type 4", /* KB_SUN4 == 0x04 && layout == 0 */
"generic ASCII terminal", /* KB_ASCII == 0x0F [5] */
"Sun type 5 unknown", /* KB_SUN4 && layout not in [33,49] */
"Sun type 5 PC", /* KB_SUN4 && layout == 33 */
"Sun type 5 Unix", /* KB_SUN4 && layout == 34 */
"Sun type 5 French", /* KB_SUN4 && layout == 35 */
"Sun type 5 Danish", /* KB_SUN4 && layout == 36 */
"Sun type 5 German", /* KB_SUN4 && layout == 37 */
"Sun type 5 Italian", /* KB_SUN4 && layout == 38 */
"Sun type 5 Dutch", /* KB_SUN4 && layout == 39 */
"Sun type 5 Norwegian", /* KB_SUN4 && layout == 40 */
"Sun type 5 Portuguese", /* KB_SUN4 && layout == 41 */
"Sun type 5 Spanish", /* KB_SUN4 && layout == 42 */
"Sun type 5 Swedish/Finnish", /* KB_SUN4 && layout == 43 */
"Sun type 5 Swiss/French", /* KB_SUN4 && layout == 44 */
"Sun type 5 Swiss/German", /* KB_SUN4 && layout == 45 */
"Sun type 5 UK", /* KB_SUN4 && layout == 46 */
"Sun type 5 Korean", /* KB_SUN4 && layout == 47 */
"Sun type 5 Taiwanese", /* KB_SUN4 && layout == 48 */
"Sun type 5 Nihon-go", /* KB_SUN4 && layout == 49 */
0
};
#define type5index(x) ((32 < (x) && (x) < 50) ? ((x) - 33 + 7) : 6)
main()
{
int ktype = kbdtype();
(void) puts((ktype >= 0) ? kbdname[ktype] : "unknown");
return 0;
}
int
kbdtype()
{
int fd;
int status = 0;
int ktype;
int layout;
if ((fd = open("/dev/kbd", O_RDONLY)) < 0)
return -1;
if (ioctl(fd, KIOCTYPE, &ktype) < 0)
{
(void) close(fd);
return -1;
}
if (ktype == KB_SUN4 && ioctl(fd, KIOCLAYOUT, &layout) < 0)
{
(void) close(fd);
return -1;
}
if (ktype < KB_SUN4)
return ktype;
if (ktype == KB_ASCII)
return 5;
if (ktype > KB_ASCII)
return -1;
/* beyond here it must be a Sun type 5 of some sort */
if (layout == 0)
return ktype;
return type5index(layout);
}
--- CUT HERE ---
-- Michael Khaw khaw@parcplace.com (or khaw%parcplace.com@netcom.com) ParcPlace Systems, Sunnyvale, CA PRODUCT INFO: info@parcplace.com--------------------------------------------------------------------- My X11R5 directory has kbd_mode, but not kbdtype. Haven't checked old stuff yet. The person I posted this for just found a kludgy way to do it with xmodmap. It only works under X though, making the above better solutions. However, if the server knows, it has to be somewhere in the X11R5 code. Maybe it moved in R5 ?
> From: rj@rainbow.in-berlin.de (Robert Joop)
try <your X11R5 directory>/mit/server/ddx/sun/kbdtype, source is in the same directory.
rj -- =
Robert Joop rj@{rainbow.in-berlin,fokus.gmd,cs.tu-berlin}.de s=3Djoop;ou=3Dfokus;ou=3Dberlin;p=3Dgmd;a=3Ddbp;c=3Dde
---------------------------------------------------------------------
Thank you for all your help !
Clayton Castle (cwc@netcom.com)
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:07:58 CDT