#define SUBMODEL 1
#include "mydef.h"
#include "wscreen.h"
#define RIGHTSHIFT 0x0001
#define LEFTSHIFT 0x0002
#define CONTROL 0x0004
#define ALT 0x0008
#define SCROLLSTATE 0x0010
#define NUMLOCKSTATE 0x0020
#define CAPLOCKSTATE 0x0040
#define INSERTSTATE 0x0080
#define CTRLNUMLKSTATE 0x0800
#define SCROLLLOCK 0x1000
#define NUMLOCK 0x2000
#define CAPSLOCK 0x4000
#define INSERT 0x8000
#ifndef BITSPERBYTE
#define BITSPERBYTE 8
#endif
#define IS_MSB(x) ((x) & (1 << ((sizeof((x)) * BITSPERBYTE) -
1)))
#define NUM_ELEMENTS(x) (sizeof((x)) / sizeof((x)[0]))
int BiosKey(int cmd)
{
INPUT_RECORD ib;
PINPUT_RECORD pir;
DWORD dwConsoleMode;
int nRet, j, i;
int JustModifier;
DWORD Read, dwRead, dwCnt;
memset( &ib, 0, sizeof( INPUT_RECORD ) );
switch(cmd) {
case 0x00:
case 0x10:
do {
ReadConsoleInpu t( hInput, &ib, 1, &Read );
JustModifier = (ib.Event.KeyEv ent.wVirtualKey Code>=16)
&& (ib.Event.KeyEv ent.wVirtualKey Code<=18);
if ( !ib.Event.KeyEv ent.bKeyDown )
Read = 0;
} while( Read==0 || ib.EventType!=K EY_EVENT || JustModifier
);
i=translate_key ( ib );
return(i);
case 0x01:
case 0x11:
nRet = 0;
if(!GetNumberOf ConsoleInputEve nts(hInput, &dwRead))
return(0);
if (!dwRead) return(0);
if (NULL == (pir = (PINPUT_RECORD) HeapAlloc(GetPr ocessHeap(),
0, dwRead * sizeof(*pir))))
return(0);
if (PeekConsoleInp utA(hInput, pir, dwRead, &dwRead)) {
for (dwCnt = 0; dwCnt < dwRead; ++dwCnt) {
if ((KEY_EVENT == pir[dwCnt].EventType) &&
(pir[dwCnt].Event.KeyEvent .bKeyDown))
{ if ((VK_PAUSE ==
pir[dwCnt].Event.KeyEvent .wVirtualKeyCod e) &&
(pir[dwCnt].Event.KeyEvent .dwControlKeySt ate &
(LEFT_CTRL_PRES SED | RIGHT_CTRL_PRES SED)))
nRet = -1;
else
nRet =
MW(pir[dwCnt].Event.KeyEvent .uChar.AsciiCha r,
pir[dwCnt].Event.KeyEvent .wVirtualScanCo de);
break;
}
}
}
HeapFree(GetPro cessHeap(), 0, (PVOID)pir);
return(nRet);
case 0x02:
case 0x12:
nRet=0;
if(IS_MSB(GetAs yncKeyState(VK_ RSHIFT))) nRet|=RIGHTSHIF T;
if(IS_MSB(GetAs yncKeyState(VK_ LSHIFT))) nRet|=LEFTSHIFT ;
if(IS_MSB(GetAs yncKeyState(VK_ CONTROL))) nRet|=CONTROL;
if(IS_MSB(GetAs yncKeyState(VK_ MENU))) nRet|=ALT;
if(IS_MSB(GetAs yncKeyState(VK_ SCROLL))) nRet|=SCROLLSTA TE;
if(IS_MSB(GetAs yncKeyState(VK_ NUMLOCK)))
nRet|=NUMLOCKST ATE;
if(IS_MSB(GetAs yncKeyState(VK_ CAPITAL)))
nRet|=CAPLOCKST ATE;
if(IS_MSB(GetAs yncKeyState(VK_ INSERT))) nRet|=INSERTSTA TE;
if (nRet) Flush();
return(nRet);
default:
break;
}
return(0);
}
int dio_kbhit(void) {
if (chbuf!=EOF) return 1;
return BiosKey(1);
}
int dio_getch( void )
{ static unsigned int key=0xffff;
if (chbuf!=EOF)
{ key=chbuf;
chbuf=EOF;
return (key);
}
if ((key & 0xff) == 0 || (key & 0xff) == 0xe0 ) {
key++;
return (key >8) & 0x7f;
}
key = BiosKey(0);
return key & 0x7f;
}
--
DosFreak
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------