From 44b35ccf13bb66ad87ec1d1c6697ce9253610176 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 29 Dec 2011 22:25:41 +0100 Subject: [PATCH] Make Sys_GetScanTable() only available on Windows Sys_GetScanTable() and MapKey() are only used by the Windows backend or the Windows-only tools. Rename to Win_GetScanTable() and move MapKey() as Win_MapKey() to win_input.cpp. --- neo/sys/sys_public.h | 1 - neo/sys/win32/win_input.cpp | 90 ++++++++++++++++++++++++++++++++++- neo/sys/win32/win_local.h | 3 +- neo/sys/win32/win_syscon.cpp | 4 +- neo/sys/win32/win_wndproc.cpp | 90 +---------------------------------- neo/tools/guied/GEViewer.cpp | 2 +- 6 files changed, 95 insertions(+), 95 deletions(-) diff --git a/neo/sys/sys_public.h b/neo/sys/sys_public.h index 66bbff66..2a7bf692 100644 --- a/neo/sys/sys_public.h +++ b/neo/sys/sys_public.h @@ -205,7 +205,6 @@ char *Sys_ConsoleInput( void ); void Sys_InitInput( void ); void Sys_ShutdownInput( void ); void Sys_InitScanTable( void ); -const unsigned char *Sys_GetScanTable( void ); unsigned char Sys_GetConsoleKey( bool shifted ); // map a scancode key to a char // does nothing on win32, as SE_KEY == SE_CHAR there diff --git a/neo/sys/win32/win_input.cpp b/neo/sys/win32/win_input.cpp index 74a053dd..fa31b473 100644 --- a/neo/sys/win32/win_input.cpp +++ b/neo/sys/win32/win_input.cpp @@ -738,13 +738,99 @@ void Sys_InitScanTable( void ) { /* ================== -Sys_GetScanTable +Win_GetScanTable ================== */ -const unsigned char *Sys_GetScanTable( void ) { +const unsigned char *Win_GetScanTable( void ) { return keyScanTable; } +/* +======= +Win_MapKey + +Map from windows to Doom keynums +======= +*/ +int Win_MapKey (int key) +{ + int result; + int modified; + bool is_extended; + + modified = ( key >> 16 ) & 255; + + if ( modified > 127 ) + return 0; + + if ( key & ( 1 << 24 ) ) { + is_extended = true; + } + else { + is_extended = false; + } + + //Check for certain extended character codes. + //The specific case we are testing is the numpad / is not being translated + //properly for localized builds. + if(is_extended) { + switch(modified) { + case 0x35: //Numpad / + return K_KP_SLASH; + } + } + + const unsigned char *scanToKey = Win_GetScanTable(); + result = scanToKey[modified]; + + // common->Printf( "Key: 0x%08x Modified: 0x%02x Extended: %s Result: 0x%02x\n", key, modified, (is_extended?"Y":"N"), result); + + if ( is_extended ) { + switch ( result ) + { + case K_PAUSE: + return K_KP_NUMLOCK; + case 0x0D: + return K_KP_ENTER; + case 0x2F: + return K_KP_SLASH; + case 0xAF: + return K_KP_PLUS; + case K_KP_STAR: + return K_PRINT_SCR; + case K_ALT: + return K_RIGHT_ALT; + } + } + else { + switch ( result ) + { + case K_HOME: + return K_KP_HOME; + case K_UPARROW: + return K_KP_UPARROW; + case K_PGUP: + return K_KP_PGUP; + case K_LEFTARROW: + return K_KP_LEFTARROW; + case K_RIGHTARROW: + return K_KP_RIGHTARROW; + case K_END: + return K_KP_END; + case K_DOWNARROW: + return K_KP_DOWNARROW; + case K_PGDN: + return K_KP_PGDN; + case K_INS: + return K_KP_INS; + case K_DEL: + return K_KP_DEL; + } + } + + return result; +} + /* =============== Sys_GetConsoleKey diff --git a/neo/sys/win32/win_local.h b/neo/sys/win32/win_local.h index 64b06785..5ac443cb 100644 --- a/neo/sys/win32/win_local.h +++ b/neo/sys/win32/win_local.h @@ -67,7 +67,8 @@ char *Sys_GetCurrentUser( void ); void Win_SetErrorText( const char *text ); -int MapKey (int key); +const unsigned char *Win_GetScanTable( void ); +int Win_MapKey (int key); // Input subsystem diff --git a/neo/sys/win32/win_syscon.cpp b/neo/sys/win32/win_syscon.cpp index 1ccb0da3..703358b5 100644 --- a/neo/sys/win32/win_syscon.cpp +++ b/neo/sys/win32/win_syscon.cpp @@ -206,7 +206,7 @@ LONG WINAPI InputLineWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam break; case WM_KEYDOWN: - key = MapKey( lParam ); + key = Win_MapKey( lParam ); // command history if ( ( key == K_UPARROW ) || ( key == K_KP_UPARROW ) ) { @@ -234,7 +234,7 @@ LONG WINAPI InputLineWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam break; case WM_CHAR: - key = MapKey( lParam ); + key = Win_MapKey( lParam ); GetWindowText( s_wcd.hwndInputLine, s_wcd.consoleField.GetBuffer(), MAX_EDIT_LINE ); SendMessage( s_wcd.hwndInputLine, EM_GETSEL, (WPARAM) NULL, (LPARAM) &cursor ); diff --git a/neo/sys/win32/win_wndproc.cpp b/neo/sys/win32/win_wndproc.cpp index bdf552bc..f779abbb 100644 --- a/neo/sys/win32/win_wndproc.cpp +++ b/neo/sys/win32/win_wndproc.cpp @@ -180,92 +180,6 @@ static byte s_scantoshift[128] = }; -/* -======= -MapKey - -Map from windows to Doom keynums -======= -*/ -int MapKey (int key) -{ - int result; - int modified; - bool is_extended; - - modified = ( key >> 16 ) & 255; - - if ( modified > 127 ) - return 0; - - if ( key & ( 1 << 24 ) ) { - is_extended = true; - } - else { - is_extended = false; - } - - //Check for certain extended character codes. - //The specific case we are testing is the numpad / is not being translated - //properly for localized builds. - if(is_extended) { - switch(modified) { - case 0x35: //Numpad / - return K_KP_SLASH; - } - } - - const unsigned char *scanToKey = Sys_GetScanTable(); - result = scanToKey[modified]; - - // common->Printf( "Key: 0x%08x Modified: 0x%02x Extended: %s Result: 0x%02x\n", key, modified, (is_extended?"Y":"N"), result); - - if ( is_extended ) { - switch ( result ) - { - case K_PAUSE: - return K_KP_NUMLOCK; - case 0x0D: - return K_KP_ENTER; - case 0x2F: - return K_KP_SLASH; - case 0xAF: - return K_KP_PLUS; - case K_KP_STAR: - return K_PRINT_SCR; - case K_ALT: - return K_RIGHT_ALT; - } - } - else { - switch ( result ) - { - case K_HOME: - return K_KP_HOME; - case K_UPARROW: - return K_KP_UPARROW; - case K_PGUP: - return K_KP_PGUP; - case K_LEFTARROW: - return K_KP_LEFTARROW; - case K_RIGHTARROW: - return K_KP_RIGHTARROW; - case K_END: - return K_KP_END; - case K_DOWNARROW: - return K_KP_DOWNARROW; - case K_PGDN: - return K_KP_PGDN; - case K_INS: - return K_KP_INS; - case K_DEL: - return K_KP_DEL; - } - } - - return result; -} - /* ==================== @@ -386,7 +300,7 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { } // fall through for other keys case WM_KEYDOWN: - key = MapKey( lParam ); + key = Win_MapKey( lParam ); if ( key == K_CTRL || key == K_ALT || key == K_RIGHT_ALT ) { // let direct-input handle this because windows sends Alt-Gr // as two events (ctrl then alt) @@ -397,7 +311,7 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { case WM_SYSKEYUP: case WM_KEYUP: - key = MapKey( lParam ); + key = Win_MapKey( lParam ); if ( key == K_PRINT_SCR ) { // don't queue printscreen keys. Since windows doesn't send us key // down events for this, we handle queueing them with DirectInput diff --git a/neo/tools/guied/GEViewer.cpp b/neo/tools/guied/GEViewer.cpp index 46113ad4..276c3be6 100644 --- a/neo/tools/guied/GEViewer.cpp +++ b/neo/tools/guied/GEViewer.cpp @@ -179,7 +179,7 @@ static int MapKey (int key) is_extended = false; } - const unsigned char *scanToKey = Sys_GetScanTable(); + const unsigned char *scanToKey = Win_GetScanTable(); result = scanToKey[modified]; // common->Printf( "Key: 0x%08x Modified: 0x%02x Extended: %s Result: 0x%02x\n", key, modified, (is_extended?"Y":"N"), result);