diff --git a/SmartContextMenu/Hooks/KeyboardHook.cs b/SmartContextMenu/Hooks/KeyboardHook.cs index 2293ba4..a4a8ce1 100644 --- a/SmartContextMenu/Hooks/KeyboardHook.cs +++ b/SmartContextMenu/Hooks/KeyboardHook.cs @@ -72,8 +72,13 @@ private int HookProc(int code, IntPtr wParam, ref KeyboardLLHookStruct lParam) { if (wParam.ToInt32() == WM_KEYDOWN || wParam.ToInt32() == WM_SYSKEYDOWN) { - foreach (var item in MenuItems.Items.Flatten(x => x.Items).Where(x => x.Type == MenuItemType.Item)) + foreach (var item in MenuItems.Items.Flatten(x => x.Items).Where(x => x.Show && x.Type == MenuItemType.Item)) { + if (item.Key3 == VirtualKey.None || lParam.vkCode != (int)item.Key3) + { + continue; + } + var key1 = true; var key2 = true; @@ -89,7 +94,7 @@ private int HookProc(int code, IntPtr wParam, ref KeyboardLLHookStruct lParam) key2 = Convert.ToBoolean(key2State); } - if (key1 && key2 && lParam.vkCode == (int)item.Key3) + if (key1 && key2) { var handler = MenuItemHooked; if (handler != null) @@ -106,6 +111,11 @@ private int HookProc(int code, IntPtr wParam, ref KeyboardLLHookStruct lParam) foreach (var item in MenuItems.WindowSizeItems) { + if (item.Key3 == VirtualKey.None || lParam.vkCode != (int)item.Key3) + { + continue; + } + var key1 = true; var key2 = true; @@ -121,7 +131,7 @@ private int HookProc(int code, IntPtr wParam, ref KeyboardLLHookStruct lParam) key2 = Convert.ToBoolean(key2State); } - if (key1 && key2 && lParam.vkCode == (int)item.Key3) + if (key1 && key2) { var handler = WindowSizeMenuItemHooked; if (handler != null) diff --git a/SmartContextMenu/Hooks/MouseHook.cs b/SmartContextMenu/Hooks/MouseHook.cs index 5126892..05a043f 100644 --- a/SmartContextMenu/Hooks/MouseHook.cs +++ b/SmartContextMenu/Hooks/MouseHook.cs @@ -74,10 +74,9 @@ private int HookProc(int code, int wParam, IntPtr lParam) { if (code == HC_ACTION) { - if (MouseButton != MouseButton.None && - (wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN || - wParam == WM_MBUTTONDOWN || wParam == WM_LBUTTONUP || - wParam == WM_RBUTTONUP || wParam == WM_MBUTTONUP)) + if ((MouseButton == MouseButton.Left && wParam == WM_LBUTTONDOWN) || + (MouseButton == MouseButton.Right && wParam == WM_RBUTTONDOWN) || + (MouseButton == MouseButton.Middle && wParam == WM_MBUTTONDOWN)) { var key1 = true; var key2 = true; @@ -108,10 +107,7 @@ private int HookProc(int code, int wParam, IntPtr lParam) key4 = Convert.ToBoolean(keyState); } - if (key1 && key2 && key3 && key4 && - ((MouseButton == MouseButton.Left && wParam == WM_LBUTTONDOWN) || - (MouseButton == MouseButton.Right && wParam == WM_RBUTTONDOWN) || - (MouseButton == MouseButton.Middle && wParam == WM_MBUTTONDOWN))) + if (key1 && key2 && key3 && key4) { var handler = Hooked; if (handler != null) @@ -120,14 +116,14 @@ private int HookProc(int code, int wParam, IntPtr lParam) return 1; } } + } - if (wParam == WM_LBUTTONDOWN) + if (MouseButton != MouseButton.None && wParam == WM_LBUTTONDOWN) + { + var handler = ClickHooked; + if (handler != null) { - var handler = ClickHooked; - if (handler != null) - { - handler.BeginInvoke(this, EventArgs.Empty, null, null); - } + handler.BeginInvoke(this, EventArgs.Empty, null, null); } } }