src/arch/mswin/mycurses.c
/* Caller can request either 8-bit input (ReadConsoleInputA) or 16-bit input (ReadConsoleInputW) */
Caller can request either 8-bit input (ReadConsoleInputA) or 16-bit input (ReadConsoleInputW)
Caller can request either 8 - bit input ( ReadConsoleInputA ) or 16 - bit input ( ReadConsoleInputW )
static int mycur_getc(WBITS wbits)
{
	static struct keycvt keymap[] = {
		{ VK_DOWN, KEY_DOWN }
		, { VK_UP, KEY_UP }
		, { VK_NEXT, KEY_NPAGE }
		, { VK_PRIOR, KEY_PPAGE }
		, { VK_HOME, KEY_HOME }
		, { VK_END, KEY_END }
		, { VK_RETURN, KEY_ENTER }
	};
	static struct keycvt skeymap[] = {
		{ VK_NEXT, KEY_SNEXT }
		, { VK_PRIOR, KEY_SPREVIOUS }
		, { VK_HOME, KEY_SHOME }
	};
	static int altctrls = LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED;
	static int numpadbase=0;
	static int numpadval=0;
	if (hStdin == INVALID_HANDLE_VALUE || redirected_in)
		return getchar();
	while (1)
	{
		INPUT_RECORD inrec;
		int nrecs=0, i;
		if (WindowsNt && wbits==W16BITS)
		{
			(*ApiReadConsoleInput)(hStdin, &inrec, 1, &nrecs);
		}
		else
		{
			ReadConsoleInput(hStdin, &inrec, 1, &nrecs);
		}
		if (!nrecs)
			return EOF;
		check_for_resize();
		if (inrec.EventType == KEY_EVENT && inrec.Event.KeyEvent.bKeyDown
			&& inrec.Event.KeyEvent.wVirtualKeyCode != VK_MENU)
		{
			int keystate, keycode;
			if (WindowsNt && wbits==W16BITS)
			{
				if (inrec.Event.KeyEvent.uChar.UnicodeChar)
				{
					unsigned int ch = (wchar_t)inrec.Event.KeyEvent.uChar.UnicodeChar;
					return ch;
				}
			}
			else
			{
				if (inrec.Event.KeyEvent.uChar.AsciiChar)
				{
					unsigned int ch = (unsigned char)inrec.Event.KeyEvent.uChar.AsciiChar;
					return ch;
				}
			}
			keystate = inrec.Event.KeyEvent.dwControlKeyState;
			keycode = inrec.Event.KeyEvent.wVirtualKeyCode;
			if ((keystate & LEFT_ALT_PRESSED || keystate & RIGHT_ALT_PRESSED)
				&& (VK_NUMPAD0 <= keycode && keycode <= VK_NUMPAD9))
			{
				if (!numpadval)
				{
					if (keycode == VK_NUMPAD0)
					{
						numpadbase = 8;
						numpadval = -1;
					}
					else
					{
						numpadbase = 10;
						numpadval = (keycode - VK_NUMPAD0);
					}
				}
				else
				{
					if (numpadval == -1)
						numpadval = keycode - VK_NUMPAD0;
					else
						numpadval = numpadval * numpadbase + (keycode - VK_NUMPAD0);
					if (numpadval > 127)
					{
						int val = numpadval;
						numpadval = 0;
						return val;
					}
				}
			}
			else
				numpadval = 0;
			if (!(keystate & altctrls))
			{
				if (keystate & SHIFT_PRESSED)
				{
					for (i=0; i<sizeof(skeymap)/sizeof(skeymap[0]); ++i)
					{
						if (inrec.Event.KeyEvent.wVirtualKeyCode == skeymap[i].win)
							return skeymap[i].curs;
					}
				}
				else 
				{
					for (i=0; i<sizeof(keymap)/sizeof(keymap[0]); ++i)
					{
						if (inrec.Event.KeyEvent.wVirtualKeyCode == keymap[i].win)
							return keymap[i].curs;
					}
				}
			}
			else
			{
			}
		}
	}
}
static int mycur_getc ( WBITS wbits ) { static struct keycvt keymap [ ] = { { VK_DOWN , KEY_DOWN } , { VK_UP , KEY_UP } , { VK_NEXT , KEY_NPAGE } , { VK_PRIOR , KEY_PPAGE } , { VK_HOME , KEY_HOME } , { VK_END , KEY_END } , { VK_RETURN , KEY_ENTER } } ; static struct keycvt skeymap [ ] = { { VK_NEXT , KEY_SNEXT } , { VK_PRIOR , KEY_SPREVIOUS } , { VK_HOME , KEY_SHOME } } ; static int altctrls = LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED ; static int numpadbase = 0 ; static int numpadval = 0 ; if ( hStdin == INVALID_HANDLE_VALUE || redirected_in ) return getchar ( ) ; while ( 1 ) { INPUT_RECORD inrec ; int nrecs = 0 , i ; if ( WindowsNt && wbits == W16BITS ) { ( * ApiReadConsoleInput ) ( hStdin , & inrec , 1 , & nrecs ) ; } else { ReadConsoleInput ( hStdin , & inrec , 1 , & nrecs ) ; } if ( ! nrecs ) return EOF ; check_for_resize ( ) ; if ( inrec . EventType == KEY_EVENT && inrec . Event . KeyEvent . bKeyDown && inrec . Event . KeyEvent . wVirtualKeyCode != VK_MENU ) { int keystate , keycode ; if ( WindowsNt && wbits == W16BITS ) { if ( inrec . Event . KeyEvent . uChar . UnicodeChar ) { unsigned int ch = ( wchar_t ) inrec . Event . KeyEvent . uChar . UnicodeChar ; return ch ; } } else { if ( inrec . Event . KeyEvent . uChar . AsciiChar ) { unsigned int ch = ( unsigned char ) inrec . Event . KeyEvent . uChar . AsciiChar ; return ch ; } } keystate = inrec . Event . KeyEvent . dwControlKeyState ; keycode = inrec . Event . KeyEvent . wVirtualKeyCode ; if ( ( keystate & LEFT_ALT_PRESSED || keystate & RIGHT_ALT_PRESSED ) && ( VK_NUMPAD0 <= keycode && keycode <= VK_NUMPAD9 ) ) { if ( ! numpadval ) { if ( keycode == VK_NUMPAD0 ) { numpadbase = 8 ; numpadval = -1 ; } else { numpadbase = 10 ; numpadval = ( keycode - VK_NUMPAD0 ) ; } } else { if ( numpadval == -1 ) numpadval = keycode - VK_NUMPAD0 ; else numpadval = numpadval * numpadbase + ( keycode - VK_NUMPAD0 ) ; if ( numpadval > 127 ) { int val = numpadval ; numpadval = 0 ; return val ; } } } else numpadval = 0 ; if ( ! ( keystate & altctrls ) ) { if ( keystate & SHIFT_PRESSED ) { for ( i = 0 ; i < sizeof ( skeymap ) / sizeof ( skeymap [ 0 ] ) ; ++ i ) { if ( inrec . Event . KeyEvent . wVirtualKeyCode == skeymap [ i ] . win ) return skeymap [ i ] . curs ; } } else { for ( i = 0 ; i < sizeof ( keymap ) / sizeof ( keymap [ 0 ] ) ; ++ i ) { if ( inrec . Event . KeyEvent . wVirtualKeyCode == keymap [ i ] . win ) return keymap [ i ] . curs ; } } } else { } } } }
Caller can request either 8-bit input (ReadConsoleInputA) or 16-bit input (ReadConsoleInputW)
Caller can request either 8 - bit input ( ReadConsoleInputA ) or 16 - bit input ( ReadConsoleInputW )
/* table of curses names for special keys */ /* NB: These are not single-byte constants, so return value must be int */ /* To get special keys, have to use ReadConsoleInput */ /* 2006-07-23, Perry:
		Not receiving any inrec.EventType == WINDOW_BUFFER_SIZE_EVENT)
			int width= inrec.Event.WindowBufferSizeEvent.dwSize.X;
			int height = inrec.Event.WindowBufferSizeEvent.dwSize.Y;
		*/ /* return normal keys */ /* handle keyboard numeric escapes for non-ASCII characters */ /* TODO: 0-prefixed alt-codes are not octal codes in the console
						codeset at all, but rather decimal codes but in the Windows codeset !
						2003-04-20, Perry
						*/ /* check if it is a hardware key we handle */ /* if so, map it to curses constant */ /* not shifted */