MCPcopy Create free account
hub / github.com/NetHack/NetHack / default_kbhit

Function default_kbhit

sys/windows/consoletty.c:3033–3084  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3031}
3032
3033int
3034default_kbhit(HANDLE hConIn, INPUT_RECORD *ir)
3035{
3036 int done = 0; /* true = "stop searching" */
3037 int retval; /* true = "we had a match" */
3038 DWORD count;
3039 unsigned short int scan;
3040 unsigned char ch;
3041 unsigned long shiftstate;
3042 int altseq = 0, keycode, vk;
3043 done = 0;
3044 retval = 0;
3045 while (!done) {
3046 count = 0;
3047 PeekConsoleInput(hConIn, ir, 1, &count);
3048 if (count > 0) {
3049 if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) {
3050 ch = ir->Event.KeyEvent.uChar.AsciiChar;
3051 scan = ir->Event.KeyEvent.wVirtualScanCode;
3052 shiftstate = ir->Event.KeyEvent.dwControlKeyState;
3053 vk = ir->Event.KeyEvent.wVirtualKeyCode;
3054 keycode = MapVirtualKey(vk, 2);
3055 if (shiftstate & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) {
3056 if (ch || inmap(keycode, vk))
3057 altseq = 1;
3058 else
3059 altseq = -1; /* invalid altseq */
3060 }
3061 if (ch || iskeypad(scan) || altseq) {
3062 done = 1; /* Stop looking */
3063 retval = 1; /* Found what we sought */
3064 } else {
3065 /* Strange Key event; let's purge it to avoid trouble */
3066 ReadConsoleInput(hConIn, ir, 1, &count);
3067 }
3068
3069 } else if ((ir->EventType == MOUSE_EVENT
3070 && (ir->Event.MouseEvent.dwButtonState
3071 & MOUSEMASK))) {
3072 done = 1;
3073 retval = 1;
3074 }
3075
3076 else /* Discard it, it's an insignificant event */
3077 ReadConsoleInput(hConIn, ir, 1, &count);
3078 } else /* There are no events in console event queue */ {
3079 done = 1; /* Stop looking */
3080 retval = 0;
3081 }
3082 }
3083 return retval;
3084}
3085
3086int
3087default_checkinput(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected