Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix modifier key up is not detected sometimes #868

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions SuperPutty/frmSuperPutty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ public partial class frmSuperPutty : Form
private FormWindowState lastNonMinimizedWindowState = FormWindowState.Normal;
private Rectangle lastNormalDesktopBounds;
private ChildWindowFocusHelper focusHelper;
bool isControlDown = false;
bool isShiftDown = false;
bool isAltDown = false;
bool isWinDown = false;
int commandMRUIndex = -1;

private readonly TabSwitcher tabSwitcher;
Expand Down Expand Up @@ -1285,6 +1281,11 @@ private static IntPtr SetKBHook(NativeMethods.LowLevelKMProc proc)

private IntPtr foregroundBeforeWinDown = IntPtr.Zero;

private static bool GetKeyDown(Keys keyCode)
{
return NativeMethods.GetKeyState((int)keyCode) < 0;
}

// Intercept keyboard messages for Ctrl-F4 and Ctrl-Tab handling
private IntPtr KBHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
Expand All @@ -1293,12 +1294,12 @@ private IntPtr KBHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
int vkCode = Marshal.ReadInt32(lParam);
Keys keys = (Keys)vkCode;

// track key state globally for control/alt/shift is up/down
// get key state of control/alt/shift is up/down
bool isKeyDown = wParam == (IntPtr)NativeMethods.WM_KEYDOWN || wParam == (IntPtr)NativeMethods.WM_SYSKEYDOWN;
if (keys == Keys.LControlKey || keys == Keys.RControlKey) { isControlDown = isKeyDown; }
if (keys == Keys.LShiftKey || keys == Keys.RShiftKey) { isShiftDown = isKeyDown; }
if (keys == Keys.LMenu || keys == Keys.RMenu) { isAltDown = isKeyDown; }
if (keys == Keys.LWin || keys == Keys.RWin) { isWinDown = isKeyDown; }
bool isControlDown = GetKeyDown(Keys.LControlKey) || GetKeyDown(Keys.RControlKey);
bool isShiftDown = GetKeyDown(Keys.LShiftKey) || GetKeyDown(Keys.RShiftKey);
bool isAltDown = GetKeyDown(Keys.LMenu) || GetKeyDown(Keys.RMenu);
bool isWinDown = GetKeyDown(Keys.LWin) || GetKeyDown(Keys.RWin);

if (Log.Logger.IsEnabledFor(Level.Trace))
{
Expand Down