home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
MM1
/
DRIVERS
/
windio56.lzh
/
EXAMPLES
/
testkysns.c
< prev
Wrap
C/C++ Source or Header
|
1995-01-31
|
4KB
|
165 lines
/*
* sample code to test _gs_kysns (windio #54)
* requires kysns.h and cgfx.l
*
* NOTE: This code eats quite a bit of CPU time.
*/
#include <stdio.h>
/* macros for _gs_kysns() */
int _gs_kysns();
/* keys returned */
#define KS_SHIFT (1<<0) /* Shift key (either) */
#define KS_CTRL (1<<1) /* CTRL key */
#define KS_ALT (1<<2) /* ALT key */
#define KS_UP (1<<3) /* Up Arrow key */
#define KS_DOWN (1<<4) /* Down Arrow key */
#define KS_LEFT (1<<5) /* Left Arrow key */
#define KS_RIGHT (1<<6) /* Right Arrow key */
#define KS_SPACE (1<<7) /* Space key */
#define KS_ARROW (KS_UP | KS_DOWN | KS_RIGHT | KS_LEFT) /* Any arrow key */
#define KS_LSHIFT (1<<8) /* Left Shift */
#define KS_RSHIFT (1<<9) /* Right Shift */
#define KS_ESC (1<<10) /* ESC */
#define KS_BACKSPACE (1<<11) /* Backspace */
#define KS_TAB (1<<12) /* TAB */
#define KS_CAPSLOCK (1<<16) /* CAPS Lock */
#define KS_SCROLL (1<<17) /* Scroll Lock */
#define KS_NUMLOCK (1<<18) /* NUM Lock */
#define KS_KEYPAD (1<<19) /* Keypad Key */
#define KS_ALTKEYPAD (1<<20) /* Alternate KeyPad Key */
#define KS_INVALID (1<<31) /* is invalid for this window */
/* key test macros */
#define IS_SHIFT(x) (x & KS_SHIFT)
#define IS_KEYPAD(x) (x & KS_KEYPAD)
#define IS_ALTKEYPAD(x) (x & KS_ALTKEYPAD)
#define IS_CTRL(x) (x & KS_CTRL)
#define IS_ALT(x) (x & KS_ALT)
#define IS_UP(x) (x & KS_UP)
#define IS_DOWN(x) (x & KS_DOWN)
#define IS_LEFT(x) (x & KS_LEFT)
#define IS_RIGHT(x) (x & KS_RIGHT)
#define IS_ARROW(x) (x & KS_ARROW)
#define IS_SPACE(x) (x & KS_SPACE)
#define IS_LSHIFT(x) (x & KS_LSHIFT)
#define IS_RSHIFT(x) (x & KS_RSHIFT)
#define IS_ESC(x) (x & KS_ESC)
#define IS_BACKSPACE(x) (x & KS_BACKSPACE)
#define IS_TAB(x) (x & KS_TAB)
#define IS_CAPSLOCK(x) (x & KS_CAPSLOCK)
#define IS_SCROLL(x) (x & KS_SCROLL)
#define IS_NUMLOCK(x) (x & KS_NUMLOCK)
#define IS_INVALID(x) (x & KS_INVALID)
#define IS_VALID(x) !IS_INVALID(x)
#define IS_NOKEY(x) !(x & ~(KS_INVALID))
main()
{
int key;
char c;
for (;;) {
tsleep(20); /* sleep a bit */
if (_gs_kysns(1, &key) == -1) {
printf("This call requires windio #54 or greater!\n");
exit(0);
} else {
if (IS_INVALID(key)) { /* invalid */
/* go back to sleep */
continue;
}
if (IS_KEYPAD(key)) { /* keypad key down? */
printf("KeyPAD ");
}
if (IS_ALTKEYPAD(key)) { /* alternate keypad key down? */
printf("AltKeyPAD ");
}
if (IS_LEFT(key)) { /* left key down? */
printf("Left ");
}
if (IS_RIGHT(key)) { /* right key down? */
printf("Right ");
}
if (IS_UP(key)) { /* up key down? */
printf("Up ");
}
if (IS_DOWN(key)) { /* down key down? */
printf("Down ");
}
if (IS_SPACE(key)) { /* space key down? */
printf("Space ");
}
if (IS_SHIFT(key)) { /* either shift down? */
printf("Shift ");
}
if (IS_LSHIFT(key)) { /* left shift down? */
printf("LShift ");
}
if (IS_RSHIFT(key)) { /* right shift down? */
printf("RShift ");
}
if (IS_CTRL(key)) { /* ctrl down? */
printf("CTRL ");
}
if (IS_ALT(key)) { /* alt down? */
printf("ALT ");
}
if (IS_ESC(key)) { /* esc down? */
printf("ESC ");
}
if (IS_BACKSPACE(key)) { /* backspace down? */
printf("BACKSPACE ");
}
if (IS_TAB(key)) { /* tab key down? */
printf("TAB ");
}
if (IS_CAPSLOCK(key)) { /* capslock down? */
printf("CAPS Lock ");
}
if (IS_SCROLL(key)) { /* capslock down? */
printf("SCROLL Lock ");
}
if (IS_NUMLOCK(key)) { /* num lock down? */
printf("NUM Lock ");
}
if (!IS_NOKEY(key)) { /* no key down? */
printf("\n");
}
}
}
}
#include <types.h>
#include <machine/reg.h>
#define DS_KySns 173
#define I_SetStt 0x8e
#define I_GetStt 0x8d
_gs_kysns(path, key)
int path, /* Path to window */
*key;
{
REGISTERS reg;
reg.d[0] = path;
reg.d[1] = DS_KySns;
if (_osk(I_GetStt,®) == -1) {
return(-1);
}
*key = reg.d[0];
return(0);
}