@@ -2853,6 +2853,34 @@ static BOOL WINAPI SetWindowCompositionAttribute2( HWND hwnd, WINCOMPATTRDATA *p
2853
2853
return SetWindowCompositionAttribute (hwnd,pAttrData);
2854
2854
}
2855
2855
2856
+ // /////////////////////////////////////////////////////////////////////////////
2857
+ // hooks for preventing shell hotkeys registration on Win11
2858
+
2859
+ using ShellRegisterHotKey_t = BOOL(WINAPI*)(HWND, int , UINT, UINT, HWND);
2860
+
2861
+ static IatHookData* g_ShellRegisterHotKeyHook;
2862
+ static ShellRegisterHotKey_t g_ShellRegisterHotKey;
2863
+
2864
+ static BOOL WINAPI ShellRegisterHotKeyHook (HWND hWnd, int id, UINT fsModifiers, UINT vk, HWND hWndTarget)
2865
+ {
2866
+ // Win key
2867
+ if (fsModifiers == MOD_WIN && vk == 0 )
2868
+ return FALSE ;
2869
+
2870
+ // Ctrl+Esc
2871
+ if (fsModifiers == MOD_CONTROL && vk == VK_ESCAPE)
2872
+ return FALSE ;
2873
+
2874
+ return g_ShellRegisterHotKey (hWnd, id, fsModifiers, vk, hWndTarget);
2875
+ }
2876
+
2877
+ // one-time APC function to unregister shell hotkeys
2878
+ void NTAPI DisableShellHotkeysFunc (ULONG_PTR Parameter)
2879
+ {
2880
+ UnregisterHotKey (NULL , 1 );
2881
+ UnregisterHotKey (NULL , 2 );
2882
+ }
2883
+
2856
2884
// /////////////////////////////////////////////////////////////////////////////
2857
2885
2858
2886
static void OpenCortana ( void )
@@ -2951,8 +2979,33 @@ static void InitStartMenuDLL( void )
2951
2979
g_ProgHook=SetWindowsHookEx (WH_GETMESSAGE,HookProgManThread,NULL ,progThread);
2952
2980
g_StartHook=SetWindowsHookEx (WH_GETMESSAGE,HookDesktopThread,NULL ,GetCurrentThreadId ());
2953
2981
if (IsWin11 ())
2982
+ {
2954
2983
g_StartMouseHook=SetWindowsHookEx (WH_MOUSE,HookDesktopThreadMouse,NULL ,GetCurrentThreadId ());
2955
2984
2985
+ // hook ShellRegisterHotKey to prevent twinui.dll to install shell hotkeys (Win, Ctrl+Esc)
2986
+ // without these hotkeys there is standard WM_SYSCOMMAND+SC_TASKLIST sent when start menu is invoked by keyboard shortcut
2987
+ g_ShellRegisterHotKey = (ShellRegisterHotKey_t)GetProcAddress (GetModuleHandle (L" user32.dll" ), MAKEINTRESOURCEA (2671 ));
2988
+ auto twinui = GetModuleHandle (L" twinui.dll" );
2989
+
2990
+ if (g_ShellRegisterHotKey && twinui)
2991
+ {
2992
+ g_ShellRegisterHotKeyHook = SetIatHook (twinui, " user32.dll" ,MAKEINTRESOURCEA (2671 ), ShellRegisterHotKeyHook);
2993
+
2994
+ // unregister shell hotkeys as they may be registered already
2995
+ // this has to be done from context of thread that registered them
2996
+ auto hwnd = FindWindow (L" ApplicationManager_ImmersiveShellWindow" , NULL );
2997
+ if (hwnd)
2998
+ {
2999
+ auto thread = OpenThread (THREAD_SET_CONTEXT, FALSE , GetWindowThreadProcessId (hwnd, NULL ));
3000
+ if (thread)
3001
+ {
3002
+ QueueUserAPC (DisableShellHotkeysFunc, thread, 0 );
3003
+ CloseHandle (thread);
3004
+ }
3005
+ }
3006
+ }
3007
+ }
3008
+
2956
3009
HWND hwnd=FindWindow (L" OpenShellMenu.CStartHookWindow" ,L" StartHookWindow" );
2957
3010
LoadLibrary (L" StartMenuDLL.dll" ); // keep the DLL from unloading
2958
3011
if (hwnd) PostMessage (hwnd,WM_CLEAR,0 ,0 ); // tell the exe to unhook this hook
@@ -3150,6 +3203,8 @@ static void CleanStartMenuDLL( void )
3150
3203
g_DrawThemeTextCtlHook=NULL ;
3151
3204
ClearIatHook (g_SetWindowCompositionAttributeHook);
3152
3205
g_SetWindowCompositionAttributeHook=NULL ;
3206
+ ClearIatHook (g_ShellRegisterHotKeyHook);
3207
+ g_ShellRegisterHotKeyHook=NULL ;
3153
3208
3154
3209
CloseManagers (false );
3155
3210
ClearIatHooks ();
0 commit comments