Skip to content

Commit

Permalink
Issues #16 Fixed "Set Size" window random appearance
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderPro committed Mar 30, 2024
1 parent d1df28e commit ebb97c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
16 changes: 13 additions & 3 deletions SmartContextMenu/Hooks/KeyboardHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -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;

Expand All @@ -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)
Expand Down
24 changes: 10 additions & 14 deletions SmartContextMenu/Hooks/MouseHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit ebb97c9

Please sign in to comment.