mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-27 04:41:23 +00:00
I_GetConsoleEvents: Split KEY_EVENT code into a function of its own, like with I_GetEvent's event types
One benefit of this is that event_t data need only be created if KEY_EVENT is found, since the other event types never do anything anyway
This commit is contained in:
parent
87085f2475
commit
17a06dd6c4
1 changed files with 60 additions and 52 deletions
|
@ -590,51 +590,44 @@ static BOOL I_ReadyConsole(HANDLE ci)
|
||||||
|
|
||||||
static boolean entering_con_command = false;
|
static boolean entering_con_command = false;
|
||||||
|
|
||||||
void I_GetConsoleEvents(void)
|
static void Impl_HandleKeyboardConsoleEvent(KEY_EVENT_RECORD evt, HANDLE co)
|
||||||
{
|
{
|
||||||
event_t ev = {0,0,0,0};
|
event_t event;
|
||||||
HANDLE ci = GetStdHandle(STD_INPUT_HANDLE);
|
|
||||||
HANDLE co = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
||||||
CONSOLE_SCREEN_BUFFER_INFO CSBI;
|
CONSOLE_SCREEN_BUFFER_INFO CSBI;
|
||||||
INPUT_RECORD input;
|
|
||||||
DWORD t;
|
DWORD t;
|
||||||
|
|
||||||
while (I_ReadyConsole(ci) && ReadConsoleInput(ci, &input, 1, &t) && t)
|
memset(&event,0x00,sizeof (event));
|
||||||
|
|
||||||
|
if (evt.bKeyDown)
|
||||||
{
|
{
|
||||||
memset(&ev,0x00,sizeof (ev));
|
event.type = ev_console;
|
||||||
switch (input.EventType)
|
|
||||||
{
|
|
||||||
case KEY_EVENT:
|
|
||||||
if (input.Event.KeyEvent.bKeyDown)
|
|
||||||
{
|
|
||||||
ev.type = ev_console;
|
|
||||||
entering_con_command = true;
|
entering_con_command = true;
|
||||||
switch (input.Event.KeyEvent.wVirtualKeyCode)
|
switch (evt.wVirtualKeyCode)
|
||||||
{
|
{
|
||||||
case VK_ESCAPE:
|
case VK_ESCAPE:
|
||||||
case VK_TAB:
|
case VK_TAB:
|
||||||
ev.data1 = KEY_NULL;
|
event.data1 = KEY_NULL;
|
||||||
break;
|
break;
|
||||||
case VK_SHIFT:
|
case VK_SHIFT:
|
||||||
ev.data1 = KEY_LSHIFT;
|
event.data1 = KEY_LSHIFT;
|
||||||
break;
|
break;
|
||||||
case VK_RETURN:
|
case VK_RETURN:
|
||||||
entering_con_command = false;
|
entering_con_command = false;
|
||||||
// Fall through.
|
// Fall through.
|
||||||
default:
|
default:
|
||||||
ev.data1 = MapVirtualKey(input.Event.KeyEvent.wVirtualKeyCode,2); // convert in to char
|
event.data1 = MapVirtualKey(evt.wVirtualKeyCode,2); // convert in to char
|
||||||
}
|
}
|
||||||
if (co != INVALID_HANDLE_VALUE && GetFileType(co) == FILE_TYPE_CHAR && GetConsoleMode(co, &t))
|
if (co != INVALID_HANDLE_VALUE && GetFileType(co) == FILE_TYPE_CHAR && GetConsoleMode(co, &t))
|
||||||
{
|
{
|
||||||
if (ev.data1 && ev.data1 != KEY_LSHIFT && ev.data1 != KEY_RSHIFT)
|
if (event.data1 && event.data1 != KEY_LSHIFT && event.data1 != KEY_RSHIFT)
|
||||||
{
|
{
|
||||||
#ifdef _UNICODE
|
#ifdef _UNICODE
|
||||||
WriteConsole(co, &input.Event.KeyEvent.uChar.UnicodeChar, 1, &t, NULL);
|
WriteConsole(co, &evt.uChar.UnicodeChar, 1, &t, NULL);
|
||||||
#else
|
#else
|
||||||
WriteConsole(co, &input.Event.KeyEvent.uChar.AsciiChar, 1 , &t, NULL);
|
WriteConsole(co, &evt.uChar.AsciiChar, 1 , &t, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (input.Event.KeyEvent.wVirtualKeyCode == VK_BACK
|
if (evt.wVirtualKeyCode == VK_BACK
|
||||||
&& GetConsoleScreenBufferInfo(co,&CSBI))
|
&& GetConsoleScreenBufferInfo(co,&CSBI))
|
||||||
{
|
{
|
||||||
WriteConsoleOutputCharacterA(co, " ",1, CSBI.dwCursorPosition, &t);
|
WriteConsoleOutputCharacterA(co, " ",1, CSBI.dwCursorPosition, &t);
|
||||||
|
@ -643,17 +636,32 @@ void I_GetConsoleEvents(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ev.type = ev_keyup;
|
event.type = ev_keyup;
|
||||||
switch (input.Event.KeyEvent.wVirtualKeyCode)
|
switch (evt.wVirtualKeyCode)
|
||||||
{
|
{
|
||||||
case VK_SHIFT:
|
case VK_SHIFT:
|
||||||
ev.data1 = KEY_LSHIFT;
|
event.data1 = KEY_LSHIFT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ev.data1) D_PostEvent(&ev);
|
if (event.data1) D_PostEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void I_GetConsoleEvents(void)
|
||||||
|
{
|
||||||
|
HANDLE ci = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
HANDLE co = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
INPUT_RECORD input;
|
||||||
|
DWORD t;
|
||||||
|
|
||||||
|
while (I_ReadyConsole(ci) && ReadConsoleInput(ci, &input, 1, &t) && t)
|
||||||
|
{
|
||||||
|
switch (input.EventType)
|
||||||
|
{
|
||||||
|
case KEY_EVENT:
|
||||||
|
Impl_HandleKeyboardConsoleEvent(input.Event.KeyEvent, co);
|
||||||
break;
|
break;
|
||||||
case MOUSE_EVENT:
|
case MOUSE_EVENT:
|
||||||
case WINDOW_BUFFER_SIZE_EVENT:
|
case WINDOW_BUFFER_SIZE_EVENT:
|
||||||
|
|
Loading…
Reference in a new issue