From c14dfd767c7c1a006589a6cb2b1da96424933f38 Mon Sep 17 00:00:00 2001 From: Aldo Fregoso Date: Mon, 18 Jul 2011 22:41:13 -0500 Subject: [PATCH] Shared change with SMA, Low Level Hooks to disable Window's system shortcuts, try to press Windows Key when SM has focus :D --- src/StepMania.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/StepMania.cpp b/src/StepMania.cpp index 955fa1466e..68bf9010ed 100644 --- a/src/StepMania.cpp +++ b/src/StepMania.cpp @@ -69,7 +69,8 @@ #include "Profile.h" #if defined(WIN32) -#include +#include +#include "archutils/Win32/AppInstance.h" // used by SetWindowsHookEx -Aldo #endif void ShutdownGame(); @@ -934,6 +935,32 @@ static void ApplyLogPreferences() static LocalizedString COULDNT_OPEN_LOADING_WINDOW( "StepMania", "Couldn't open any loading windows." ); +#if defined(WIN32) +// Low Level hooks go here, I only added Windows Key, but letting the player choose which system shortcuts +// wants to get disabled via PREFSMAN would be nice -Aldo +LRESULT CALLBACK SpecialKeysHook(int code,WPARAM wparam,LPARAM lparam) +{ + if( HOOKS->AppHasFocus() ) // only disable system shortcuts when the game has focus + { + PKBDLLHOOKSTRUCT key = (PKBDLLHOOKSTRUCT)lparam; + + switch(wparam) + { + case WM_KEYDOWN: + case WM_KEYUP: + case WM_SYSKEYDOWN: + case WM_SYSKEYUP: + if(key->vkCode==VK_LWIN || key->vkCode==VK_RWIN) + { + return 1; + } + } + } + + return CallNextHookEx(0,code,wparam,lparam); +} +#endif + int main(int argc, char* argv[]) { RageThreadRegister thread( "Main thread" ); @@ -1124,6 +1151,23 @@ int main(int argc, char* argv[]) StoreActualGraphicOptions(); LOG->Info( "%s", GetActualGraphicOptionsString().c_str() ); +#if defined(WIN32) + // Apply Low Level hooks just after creating the display, so we have a valid + // HINSTANCE, rather than a NULL one -Aldo + AppInstance inst; + HHOOK hook; + hook = SetWindowsHookEx( + WH_KEYBOARD_LL, + SpecialKeysHook, + inst.Get(), + 0 + ); + if(!hook) + { + LOG->Warn("SetWindowsHookEx: Could not create hook (Error %d).", GetLastError()); + } +#endif + SONGMAN->PreloadSongImages(); /* Input handlers can have dependences on the video system so