home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ User's Journal & Wi…eveloper's Journal Tools
/
C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso
/
windbase
/
memslc.3
/
queue
/
getkey.c
next >
Wrap
C/C++ Source or Header
|
1994-12-17
|
11KB
|
277 lines
/*****************************************************************************\
** **
** WW WW IIIIIIII NNN NN DDDDDDD BBBBBBB AA SSSSSS EEEEEEEE **
** WW W WW II NNNN NN DD DD BB BB AA AA SS EE **
** WW W WW II NN NN NN DD DD BBBBBBB AAAAAAAA SSSSSS EEEEEE **
** WW W WW II NN NNNN DD DD BB BB AA AA SS EE **
** WWWWW IIIIIIII NN NNN DDDDDDD BBBBBBB AA AA SSSSSS EEEEEEEE **
** **
** SSSSSS OOOOOO FFFFFFFF TTTTTTTT WW WW AA RRRRRRR EEEEEEEE **
** SS OO OO FF TT WW W WW AA AA RR RR EE **
** SSSSS OO OO FFFFF TT WW W WW AAAAAAAA RRRRRRR EEEEEE **
** SS OO OO FF TT WW W WW AA AA RR RR EE **
** SSSSSS OOOOOO FF TT WWWWW AA AA RR RR EEEEEEEE **
** **
*********** NOTICE ************************************************************
** This file contains valuable trade secrets and proprietary **
** assets of Windbase Software Inc. Embodying substantial **
** creative efforts and confidential information. Unauthorized **
** use, copying, decompiling, translating, disclosure or **
** transfer, of any kind, is strictly prohibited. **
** **
** COPYRIGHT (C) 1992, 1993, 1994. Windbase Software Inc. **
** ALL RIGHTS RESERVED. **
\*****************************************************************************/
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#ifdef MSC
# include <sys/types.h>
# include <sys/timeb.h>
#endif
#include "../../memsl.h"
#include "getkey.h"
/*************************************************************************\
** KeyStat() is used to retrieve the current keyboard control key status.
** The check is made with the low level DOS call 0x16 (Keyboard services)
** with 'ah' set to 2. The DOS call can also be used to check the status
** of other control keys. Since all <CTRL> and <ALT> key combinations
** generate a key sequence under MS-DOS, we are only interested in the
** <SHIFT> key.
\*************************************************************************/
#ifdef WBSTDC
void KeyStat(struct key_stat *keystat)
#else
void KeyStat(keystat)
struct key_stat *keystat;
#endif
{
union REGS regs;
memset(keystat,0,sizeof(struct key_stat));
memset(®s,0,sizeof(union REGS));
regs.h.ah = 02;
int86(0x16,®s,®s);
if ((regs.h.al&0x80) == 0x80)
keystat->insert = 1;
if ((regs.h.al&0x01) == 0x01)
keystat->shiftkey = 1;
if ((regs.h.al&0x02) == 0x02)
keystat->shiftkey = 1;
}
#ifdef MSC
void delay(int milltime)
{
unsigned long time1, time2;
struct timeb timeb;
ftime(&timeb);
time1 = (unsigned long) (timeb.time*1000) + (unsigned long) timeb.millitm;
time2 = (unsigned long) (timeb.time*1000) + (unsigned long) timeb.millitm
+ (unsigned long) milltime;
while (time1 < time2)
{
ftime(&timeb);
time1 = (unsigned long) (timeb.time*1000)
+ (unsigned long) timeb.millitm;
}
}
#endif
/*************************************************************************\
** GetKey() is the main keyboard processor. GetKey() loops continuously
** until all keys are gathered from the keyboard and the keyboard is
** idle. When the keyboard is idle GetKey() will return a character with
** no delay. GetKey() translates the keypresses into the key codes as
** as defined in getkey.h. If the queue is full additional key presses
** are ignored.
\*************************************************************************/
#ifdef WBSTDC
int GetKey(WBQUEUE *keybuff)
#else
int GetKey(keybuff)
WBQUEUE *keybuff;
#endif
{
int ch;
struct key_stat keystat;
/*
** If the queue is full the key press is ignored for the moment.
** If a key has been pressed and the queue is not full, process
** the key. If no keys were pressed and the queue is empty,
** then there are no keys to return and GetKey() simply waits
** for another key to be pressed.
*/
while (WBQueueNumItems(keybuff) < WBQueueMaxItems(keybuff)
&& (kbhit() || WBQueueNumItems(keybuff) == 0))
{
switch(ch = getch())
{
case 0:
/*
** DOS returns zero along with a key code for special keys.
** For example, if the <F1> key is pressed, zero and ';'
** will be sitting in the key pool.
*/
switch(ch = getch())
{
case 59: ch = KEY_F1; break;
case 60: ch = KEY_F2; break;
case 61: ch = KEY_F3; break;
case 62: ch = KEY_F4; break;
case 63: ch = KEY_F5; break;
case 64: ch = KEY_F6; break;
case 65: ch = KEY_F7; break;
case 66: ch = KEY_F8; break;
case 67: ch = KEY_F9; break;
case 68: ch = KEY_F10; break;
case 84: ch = KEY_SF1; break;
case 85: ch = KEY_SF2; break;
case 86: ch = KEY_SF3; break;
case 87: ch = KEY_SF4; break;
case 88: ch = KEY_SF5; break;
case 89: ch = KEY_SF6; break;
case 90: ch = KEY_SF7; break;
case 91: ch = KEY_SF8; break;
case 92: ch = KEY_SF9; break;
case 93: ch = KEY_SF10; break;
case 94: ch = KEY_CF1; break;
case 95: ch = KEY_CF2; break;
case 96: ch = KEY_CF3; break;
case 97: ch = KEY_CF4; break;
case 98: ch = KEY_CF5; break;
case 99: ch = KEY_CF6; break;
case 100: ch = KEY_CF7; break;
case 101: ch = KEY_CF8; break;
case 102: ch = KEY_CF9; break;
case 103: ch = KEY_CF10; break;
case 104: ch = KEY_AF1; break;
case 105: ch = KEY_AF2; break;
case 106: ch = KEY_AF3; break;
case 107: ch = KEY_AF4; break;
case 108: ch = KEY_AF5; break;
case 109: ch = KEY_AF6; break;
case 110: ch = KEY_AF7; break;
case 111: ch = KEY_AF8; break;
case 112: ch = KEY_AF9; break;
case 113: ch = KEY_AF10; break;
case 71:
KeyStat(&keystat);
if (keystat.shiftkey)
ch = KEY_SHOME;
else
ch = KEY_HOME;
break;
case 72:
KeyStat(&keystat);
if (keystat.shiftkey)
ch = KEY_SUP;
else
ch = KEY_UP;
break;
case 73:
KeyStat(&keystat);
if (keystat.shiftkey)
ch = KEY_SPGUP;
else
ch = KEY_PGUP;
break;
case 75:
KeyStat(&keystat);
if (keystat.shiftkey)
ch = KEY_SLEFT;
else
ch = KEY_LEFT;
break;
case 77: