Simplify check for Alt-Numpad

Create two new inline functions is_alt_numpad_key(PINPUT_RECORD) and
is_alt_numpad_event(PINPUT_RECORD) which contain the actual checks.
Call these functions from fhandler_console::read and peek_console for
better readability.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen
2017-01-19 21:41:21 +01:00
parent 9985cf66e9
commit 3b7b65b2f8
3 changed files with 35 additions and 39 deletions

View File

@ -9,9 +9,34 @@ details. */
#ifndef _MISCFUNCS_H
#define _MISCFUNCS_H
#include <dinput.h>
#define likely(X) __builtin_expect (!!(X), 1)
#define unlikely(X) __builtin_expect (!!(X), 0)
/* Check for Alt+Numpad keys in a console input record. These are used to
enter codepoints not available in the current keyboard layout For details
see http://www.fileformat.info/tip/microsoft/enter_unicode.htm */
static inline bool
is_alt_numpad_key (PINPUT_RECORD pirec)
{
return pirec->Event.KeyEvent.uChar.UnicodeChar == 0
&& pirec->Event.KeyEvent.dwControlKeyState == LEFT_ALT_PRESSED
&& pirec->Event.KeyEvent.wVirtualScanCode >= DIK_NUMPAD7
&& pirec->Event.KeyEvent.wVirtualScanCode <= DIK_NUMPAD0
&& pirec->Event.KeyEvent.wVirtualScanCode != DIK_SUBTRACT;
}
/* Event for left Alt, with a non-zero character, comes from Alt+Numpad
key sequence. e.g. <left-alt> 233 => &eacute; This is typically handled
as the key up event after releasing the Alt key. */
static inline bool
is_alt_numpad_event (PINPUT_RECORD pirec)
{
return pirec->Event.KeyEvent.uChar.UnicodeChar != 0
&& pirec->Event.KeyEvent.wVirtualKeyCode == VK_MENU
&& pirec->Event.KeyEvent.wVirtualScanCode == 0x38;
}
int __reg1 winprio_to_nice (DWORD);
DWORD __reg1 nice_to_winprio (int &);