Skip to content

Commit

Permalink
Capture shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
Phaiax committed Feb 8, 2022
1 parent 8cf9e82 commit 3edada0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
6 changes: 4 additions & 2 deletions KeyNStroke/AnnotateLine.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
void m_KeystrokeEvent(KeystrokeEventArgs e)
{
string pressed = e.ShortcutIdentifier();
CheckForTrigger(pressed);
e.raw.preventDefault = e.raw.preventDefault || CheckForTrigger(pressed);
}

private void CheckForTrigger(string pressed)
private bool CheckForTrigger(string pressed)
{
if (AnnotateLineShortcut != null && pressed == AnnotateLineShortcut)
{
nextClickDraws = true;
return true;
}
return false;
}

public void SetAnnotateLineShortcut(string shortcut)
Expand Down
15 changes: 12 additions & 3 deletions KeyNStroke/KeyboardHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,19 @@ private IntPtr HookCallback(int nCode,
String.Format("Key: sc {0} vk {1} ext {2} fl {3}, {4}", lParam.scanCode,
lParam.vkCode, lParam.dwExtraInfo, lParam.flags, e.Method));
*/
if (e.preventDefault)
{
return IntPtr.Add(IntPtr.Zero, 1);
} else
{
return NativeMethodsKeyboard.CallNextHookEx(hookID, nCode, wParam, ref lParam);
}
}
else
{
//Pass key to next application
return NativeMethodsKeyboard.CallNextHookEx(hookID, nCode, wParam, ref lParam);
}
//Pass key to next application
IntPtr ret = NativeMethodsKeyboard.CallNextHookEx(hookID, nCode, wParam, ref lParam);
return ret;
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions KeyNStroke/KeyboardRawEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class KeyboardRawEventArgs
public NativeMethodsKeyboard.KBDLLHOOKSTRUCT Kbdllhookstruct;
public byte[] keyState; // 256 bytes

public bool preventDefault = false;

public KeyboardRawEventArgs(NativeMethodsKeyboard.KBDLLHOOKSTRUCT Kbdllhookstruct)
{
this.Kbdllhookstruct = Kbdllhookstruct;
Expand Down
12 changes: 8 additions & 4 deletions KeyNStroke/KeystrokeDisplay.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ void InitPeriodicTopmostTimer()
void KeystrokeEvent(KeystrokeEventArgs e)
{
string pressed = e.ShortcutIdentifier();
CheckForSettingsMode(pressed);
CheckForPasswordMode(pressed);
e.raw.preventDefault = e.raw.preventDefault || CheckForSettingsMode(pressed);
e.raw.preventDefault = e.raw.preventDefault || CheckForPasswordMode(pressed);

if (PasswordModeActivated || settings.EnablePasswordMode)
{
Expand Down Expand Up @@ -384,12 +384,14 @@ public static bool ValidateShortcutSetting(string shortcut)
return true;
}

private void CheckForSettingsMode(string pressed)
private bool CheckForSettingsMode(string pressed)
{
if (SettingsModeShortcut != null && pressed == SettingsModeShortcut)
{
settings.EnableSettingsMode = !settings.EnableSettingsMode;
return true;
}
return false;
}

bool SettingsModeActivated = false;
Expand Down Expand Up @@ -471,12 +473,14 @@ public void SetPasswordModeShortcut(string shortcut)
}


private void CheckForPasswordMode(string pressed)
private bool CheckForPasswordMode(string pressed)
{
if (PasswordModeShortcut != null && pressed == PasswordModeShortcut)
{
settings.EnablePasswordMode = !settings.EnablePasswordMode;
return true;
}
return false;
}


Expand Down

0 comments on commit 3edada0

Please sign in to comment.