2 * Copyright (C) 2000 by VTech Informations LTD.
4 * This source code is released under MPL
6 * Vladimir Cotfas <vladimircotfas@vtech.ca> Aug 31, 2000
8 * Named pipe Keyboard Driver for Microwindows
9 * See src/demos/nxkbd/srvconn.c for example client-side driver
19 #include <sys/types.h>
22 static char kbdName[] = "/tmp/.nano-X-softkbd";
23 #define KBD_NAMED_PIPE kbdName
27 static int kbd_fd = -1; /* keyboar driver FIFO */
29 static int soft_Open(KBDDEVICE* pkd);
30 static void soft_Close();
31 static void soft_GetModifierInfo(MWKEYMOD* modifiers, MWKEYMOD* curmodifiers);
32 static int soft_Read(MWKEY* buf, MWKEYMOD* modifiers, MWSCANCODE* scancode);
46 soft_Open(KBDDEVICE* pkd)
50 /* Check if the file already exists: */
51 if (!stat(KBD_NAMED_PIPE, &s)) {
52 if (unlink(KBD_NAMED_PIPE) < 0)
55 if (mkfifo(KBD_NAMED_PIPE, 0600) < 0) {
56 EPRINTF("mkfifo() error %d ('%s')\n", \
57 errno, sys_errlist[errno]);
61 /* Open the named pipe */
62 if ((kbd_fd = open(KBD_NAMED_PIPE, O_RDONLY | O_NONBLOCK)) < 0) {
63 EPRINTF("open() error %d ('%s')\n", \
64 errno, sys_errlist[errno]);
78 EPRINTF("kbd_soft.c: soft_Close(): closing named pipe %d\n", kbd_fd);
84 unlink(KBD_NAMED_PIPE);
88 * Return the possible modifiers for the keyboard.
91 soft_GetModifierInfo(MWKEYMOD* modifiers, MWKEYMOD* curmodifiers)
94 EPRINTF("kbd_soft.c: soft_GetModifierInfo(): being asked about modifiers\n");
97 *modifiers = 0; /* no modifiers available */
99 *curmodifiers = 0; /* no modifiers available */
103 * This reads one keystroke from the keyboard, and the current state of
104 * the mode keys (ALT, SHIFT, CTRL). Returns -1 on error, 0 if no data
105 * is ready, and 1 if data was read. This is a non-blocking call.
109 soft_Read(MWKEY* buf, MWKEYMOD* modifiers, MWSCANCODE* scancode)
112 *modifiers = 0; /* no modifiers yet */
113 *scancode = 0; /* no scancode yet */
115 cc = read(kbd_fd, buf, 1); /* this is NON BLOCKING read */
119 return -2; /* special case ESC*/
121 EPRINTF("kbd_soft.c: soft_Read(): read '%c', cc = %d\n",