Skip to content

Commit 10af65b

Browse files
committed
Ported all DIK_* keys to SDL2 (backwards compatible)
xrEngine/xr_input.cpp: moved keyboard update to KeyUpdate()
1 parent 388bd1e commit 10af65b

File tree

2 files changed

+306
-192
lines changed

2 files changed

+306
-192
lines changed

src/xrEngine/xr_input.cpp

Lines changed: 17 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -165,41 +165,28 @@ void CInput::MouseUpdate()
165165
}
166166
}
167167

168-
BOOL b_altF4 = FALSE;
169168
void CInput::KeyUpdate()
170169
{
171-
if (b_altF4)
172-
return;
173-
174-
const Uint8* state = SDL_GetKeyboardState(NULL);
175-
#ifndef _EDITOR
176-
bool b_alt_tab = false;
177-
178-
if (!b_altF4 && state[SDL_SCANCODE_F4] && (state[SDL_SCANCODE_RALT] || state[SDL_SCANCODE_LALT]))
170+
SDL_Event event;
171+
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYMAPCHANGED))
179172
{
180-
b_altF4 = TRUE;
181-
Engine.Event.Defer("KERNEL:disconnect");
182-
Engine.Event.Defer("KERNEL:quit");
183-
SDL_Event ev;
184-
ev.type = SDL_QUIT;
185-
SDL_PushEvent(&ev);
186-
}
187-
#endif
173+
switch (event.type)
174+
{
175+
case SDL_KEYDOWN:
176+
KBState[event.key.keysym.scancode] = true;
177+
cbStack.back()->IR_OnKeyboardPress(event.key.keysym.scancode);
178+
break;
188179

189-
#ifndef _EDITOR
190-
if (Device.dwPrecacheFrame == 0)
191-
#endif
192-
{
193-
#ifndef _EDITOR
194-
if (state[SDL_SCANCODE_TAB] && (iGetAsyncKeyState(SDL_SCANCODE_LALT) || iGetAsyncKeyState(SDL_SCANCODE_RALT)))
195-
b_alt_tab = true;
196-
#endif
180+
case SDL_KEYUP:
181+
KBState[event.key.keysym.scancode] = false;
182+
cbStack.back()->IR_OnKeyboardRelease(event.key.keysym.scancode);
183+
break;
184+
}
197185
}
198186

199-
#ifndef _EDITOR
200-
if (b_alt_tab)
201-
SDL_MinimizeWindow(Device.m_sdlWnd);
202-
#endif
187+
for (u32 i = 0; i < COUNT_KB_BUTTONS; ++i)
188+
if (KBState[i])
189+
cbStack.back()->IR_OnKeyboardHold(i);
203190
}
204191

205192
bool CInput::get_key_name(int dik, LPSTR dest_str, int dest_sz)
@@ -322,51 +309,14 @@ void CInput::OnAppDeactivate(void)
322309

323310
void CInput::OnFrame(void)
324311
{
325-
SDL_Event event;
326-
327312
stats.FrameStart();
328313
stats.FrameTime.Begin();
329314
dwCurTime = RDEVICE.TimerAsync_MMT();
330315

331316
if (Device.dwPrecacheFrame == 0)
332317
{
333318
MouseUpdate();
334-
}
335-
336-
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYMAPCHANGED))
337-
{
338-
switch (event.type)
339-
{
340-
case SDL_KEYDOWN: {
341-
KBState[event.key.keysym.scancode] = TRUE;
342-
#ifndef _EDITOR
343-
if (Device.dwPrecacheFrame == 0)
344-
#endif
345-
{
346-
cbStack.back()->IR_OnKeyboardPress(event.key.keysym.scancode);
347-
}
348-
}
349-
break;
350-
case SDL_KEYUP: {
351-
KBState[event.key.keysym.scancode] = FALSE;
352-
#ifndef _EDITOR
353-
if (Device.dwPrecacheFrame == 0)
354-
#endif
355-
{
356-
cbStack.back()->IR_OnKeyboardRelease(event.key.keysym.scancode);
357-
}
358-
}
359-
break;
360-
}
361-
}
362-
363-
#ifndef _EDITOR
364-
if (Device.dwPrecacheFrame == 0)
365-
#endif
366-
{
367-
for (u32 i = 0; i < COUNT_KB_BUTTONS; i++)
368-
if (KBState[i])
369-
cbStack.back()->IR_OnKeyboardHold(i);
319+
KeyUpdate();
370320
}
371321

372322
stats.FrameTime.End();

0 commit comments

Comments
 (0)