@@ -22,7 +22,11 @@ public static class ChefKeysManager
2222 private static bool nonRegisteredKeyDown = false ;
2323 private static bool cancelAction = false ;
2424 private static bool registeredKeyDown = false ;
25-
25+
26+ public static bool StartMenuEnableBlocking = false ;
27+ public static bool StartMenuBlocked = false ;
28+ public static string StartMenuSimulatedKey = "LeftAlt" ;
29+
2630 static ChefKeysManager ( )
2731 {
2832 registeredHotkeys = new Dictionary < int , KeyRecord > ( ) ;
@@ -187,11 +191,23 @@ private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
187191 {
188192 int vkCode = Marshal . ReadInt32 ( lParam ) ;
189193
190- var keyRecord = ! registeredHotkeys . TryGetValue ( vkCode , out KeyRecord registeredKeyRecord )
191- ? nonRegisteredKeyRecord
192- : registeredKeyRecord ;
194+ var isNotRegisteredkey = ! registeredHotkeys . TryGetValue ( vkCode , out KeyRecord registeredKeyRecord ) ;
195+
196+ var keyRecord = isNotRegisteredkey ? nonRegisteredKeyRecord : registeredKeyRecord ;
197+
198+ // Create a one-off win key record when blocking is enabled
199+ if ( StartMenuEnableBlocking && ( vkCode == VK_LWIN || vkCode == VK_RWIN ) )
200+ {
201+ keyRecord = new KeyRecord
202+ {
203+ vk_code = vkCode ,
204+ HandleKeyPress = HandleRegisteredKeyPress ,
205+ isSingleKeyRegistered = true ,
206+ action = null
207+ } ;
208+ }
193209
194- var blockKeyPress = keyRecord . HandleKeyPress ( wParam , vkCode , keyRecord ) ;
210+ var blockKeyPress = keyRecord . HandleKeyPress ( wParam , vkCode , keyRecord ) ;
195211
196212 if ( blockKeyPress )
197213 return ( IntPtr ) 1 ;
@@ -242,14 +258,14 @@ private static bool HandleRegisteredKeyPress(IntPtr wParam, int vkCode, KeyRecor
242258 {
243259 registeredKeyDown = false ;
244260
261+ StartMenuBlocked = false ;
245262 if ( vkCode == VK_LWIN || vkCode == VK_RWIN )
246263 {
247264 if ( ! cancelAction && isLWinKeyDown )
248265 {
249- SendAltKeyDown ( ) ;
250- SendLWinKeyUp ( ) ;
251- isLWinKeyDown = false ;
252- SendAltKeyUp ( ) ;
266+ BlockWindowsStartMenu ( ) ;
267+
268+ StartMenuBlocked = true ;
253269
254270 keyRecord . action ? . Invoke ( "" ) ;
255271
@@ -290,29 +306,15 @@ private static bool HandleNonRegisteredKeyPress(IntPtr wParam, int vkCode, KeyRe
290306 return false ;
291307 }
292308
293- private static void SendLWinKeyDown ( )
294- {
295- _isSimulatingKeyPress = true ;
296- keybd_event ( VK_LWIN , 0 , 0 , UIntPtr . Zero ) ;
297- _isSimulatingKeyPress = false ;
298- }
299-
300- private static void SendAltKeyDown ( )
309+ private static void BlockWindowsStartMenu ( )
301310 {
302311 _isSimulatingKeyPress = true ;
303312 keybd_event ( VK_LALT , 0 , 0 , UIntPtr . Zero ) ;
304313 _isSimulatingKeyPress = false ;
305- }
306-
307- private static void SendLWinKeyUp ( )
308- {
309314 _isSimulatingKeyPress = true ;
310315 keybd_event ( VK_LWIN , 0 , KEYEVENTF_KEYUP , UIntPtr . Zero ) ;
311316 _isSimulatingKeyPress = false ;
312- }
313-
314- private static void SendAltKeyUp ( )
315- {
317+ isLWinKeyDown = false ;
316318 _isSimulatingKeyPress = true ;
317319 keybd_event ( VK_LALT , 0 , KEYEVENTF_KEYUP , UIntPtr . Zero ) ;
318320 _isSimulatingKeyPress = false ;
0 commit comments