static char BIOSgetch() { unsigned char scan, shift, ch; const struct pad *kpad; KBDKEYINFO CharData; USHORT IOWait = 0; HKBD KbdHandle = 0; KbdCharIn(&CharData, IOWait, KbdHandle); ch = CharData.chChar; scan = CharData.chScan; shift = CharData.fsState; /* Translate keypad keys */ if (iskeypad(scan)) { kpad = iflags.num_pad ? numpad : keypad; if (shift & SHIFT_KEY) ch = kpad[scan - KEYPADLO].shift; else if (shift & CTRL_KEY) ch = kpad[scan - KEYPADLO].cntrl; else ch = kpad[scan - KEYPADLO].normal; } /* Translate unassigned Alt-letters */ if ((shift & ALT_KEY) && !ch) { if (inmap(scan)) ch = scanmap[scan - SCANLO]; return (isprint(ch) ? M(ch) : ch); } return ch; }
int __stdcall NHkbhit( HANDLE hConIn, INPUT_RECORD *ir) { int done = 0; /* true = "stop searching" */ int retval; /* true = "we had a match" */ DWORD count; unsigned short int scan; unsigned char ch; unsigned long shiftstate; int altseq = 0, keycode, vk; done = 0; retval = 0; while (!done) { count = 0; PeekConsoleInput(hConIn,ir,1,&count); if (count > 0) { if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) { ch = ir->Event.KeyEvent.uChar.AsciiChar; scan = ir->Event.KeyEvent.wVirtualScanCode; shiftstate = ir->Event.KeyEvent.dwControlKeyState; vk = ir->Event.KeyEvent.wVirtualKeyCode; keycode = MapVirtualKey(vk, 2); if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) { if (ch || inmap(keycode,vk)) altseq = 1; else altseq = -1; /* invalid altseq */ } if (ch || iskeypad(scan) || altseq) { done = 1; /* Stop looking */ retval = 1; /* Found what we sought */ } else { /* Strange Key event; let's purge it to avoid trouble */ ReadConsoleInput(hConIn,ir,1,&count); } } else if ((ir->EventType == MOUSE_EVENT && (ir->Event.MouseEvent.dwButtonState & MOUSEMASK))) { done = 1; retval = 1; } else /* Discard it, it's an insignificant event */ ReadConsoleInput(hConIn,ir,1,&count); } else /* There are no events in console event queue */ { done = 1; /* Stop looking */ retval = 0; } } return retval; }
int __stdcall ProcessKeystroke( HANDLE hConIn, INPUT_RECORD *ir, boolean *valid, boolean numberpad, int portdebug) { int metaflags = 0, k = 0; int keycode, vk; unsigned char ch, pre_ch, mk = 0; unsigned short int scan; unsigned long shiftstate; int altseq = 0; const struct pad *kpad; shiftstate = 0L; ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar; scan = ir->Event.KeyEvent.wVirtualScanCode; vk = ir->Event.KeyEvent.wVirtualKeyCode; keycode = MapVirtualKey(vk, 2); shiftstate = ir->Event.KeyEvent.dwControlKeyState; KeyState[VK_SHIFT] = (shiftstate & SHIFT_PRESSED) ? 0x81 : 0; KeyState[VK_CONTROL] = (shiftstate & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) ? 0x81 : 0; KeyState[VK_CAPITAL] = (shiftstate & CAPSLOCK_ON) ? 0x81 : 0; if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) { if (ch || inmap(keycode,vk)) altseq = 1; else altseq = -1; /* invalid altseq */ } if (ch || (iskeypad(scan)) || (altseq > 0)) *valid = TRUE; /* if (!valid) return 0; */ /* * shiftstate can be checked to see if various special * keys were pressed at the same time as the key. * Currently we are using the ALT & SHIFT & CONTROLS. * * RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED, * RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED, * SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON, * CAPSLOCK_ON, ENHANCED_KEY * * are all valid bit masks to use on shiftstate. * eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the * left control key was pressed with the keystroke. */ if (iskeypad(scan)) { kpad = numberpad ? numpad : keypad; if (shiftstate & SHIFT_PRESSED) { ch = kpad[scan - KEYPADLO].shift; } else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) { ch = kpad[scan - KEYPADLO].cntrl; } else { ch = kpad[scan - KEYPADLO].normal; } } else if (altseq > 0) { /* ALT sequence */ if (vk == 0xBF) ch = M('?'); else ch = M(tolower(keycode)); } /* Attempt to work better with international keyboards. */ else { WORD chr[2]; k = ToAscii(vk, scan, KeyState, chr, 0); if (k <= 2) switch(k) { case 2: /* two characters */ ch = (unsigned char)chr[1]; *valid = TRUE; break; case 1: /* one character */ ch = (unsigned char)chr[0]; *valid = TRUE; break; case 0: /* no translation */ default: /* negative */ *valid = FALSE; } } if (ch == '\r') ch = '\n'; #ifdef PORT_DEBUG if (portdebug) { char buf[BUFSZ]; Sprintf(buf, "PORTDEBUG (%s): ch=%u, sc=%u, vk=%d, pre=%d, sh=0x%X, ta=%d (ESC to end)", "ws_nhdefkey", ch, scan, vk, pre_ch, shiftstate, k); fprintf(stdout, "\n%s", buf); } #endif return ch; }