completed the branch

This commit is contained in:
NaBian committed 2019-05-24 00:27:40 +08:00
1 parent 6e3171259e
commit a269739949
4 files changed
+14 -49

No files matched your search

@@ -24,8 +24,8 @@
d:DesignHeight="800"
d:DesignWidth="1400">
<hc:GlobalShortcut.KeyBindings>
<KeyBinding Modifiers="Control+Alt" Key="I" Command="{Binding GlobalShortcutInfoCmd}"/>
<KeyBinding Modifiers="Control+Alt" Key="E" Command="{Binding GlobalShortcutErrorCmd}"/>
<KeyBinding Modifiers="Control+Alt" Key="I" Command="{Binding Main.GlobalShortcutInfoCmd, Source={StaticResource Locator}}"/>
<KeyBinding Modifiers="Control+Alt" Key="E" Command="{Binding Main.GlobalShortcutWarningCmd, Source={StaticResource Locator}}"/>
</hc:GlobalShortcut.KeyBindings>
<hc:Window.NonClientAreaContent>
<userControl:NoUserContent/>
@@ -102,8 +102,8 @@ namespace HandyControlDemo.ViewModel
public RelayCommand GlobalShortcutInfoCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(() => Growl.Info("Global Shortcut Info"))).Value;
public RelayCommand GlobalShortcutErrorCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(() => Growl.Info("Global Shortcut Error"))).Value;
public RelayCommand GlobalShortcutWarningCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(() => Growl.Warning("Global Shortcut Warning"))).Value;
#endregion
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using HandyControl.Data;
@@ -8,8 +7,6 @@ namespace HandyControl.Tools
{
public class GlobalShortcut
{
private static ModifierKeys ModifierKeys;
private static readonly Dictionary<string, KeyBinding> CommandDic = new Dictionary<string, KeyBinding>();
static GlobalShortcut()
@@ -21,16 +18,11 @@ namespace HandyControl.Tools
private static void HitTest(Key key)
{
Console.WriteLine(key.ToString());
if (IsModifierKey(key))
{
ModifierKeys |= GetModifierKey(key);
}
else
{
var keyStr = ModifierKeys != ModifierKeys.None ? $"{ModifierKeys.ToString()}, {key.ToString()}" : key.ToString();
ExecuteCommand(keyStr);
}
if (IsModifierKey(key)) return;
var modifierKeys = Keyboard.Modifiers;
var keyStr = modifierKeys != ModifierKeys.None ? $"{modifierKeys.ToString()}, {key.ToString()}" : key.ToString();
ExecuteCommand(keyStr);
}
private static void ExecuteCommand(string key)
@@ -47,27 +39,6 @@ namespace HandyControl.Tools
}
}
private static ModifierKeys GetModifierKey(Key key)
{
switch (key)
{
case Key.LeftCtrl:
case Key.RightCtrl:
return ModifierKeys.Control;
case Key.LeftAlt:
case Key.RightAlt:
return ModifierKeys.Alt;
case Key.LeftShift:
case Key.RightShift:
return ModifierKeys.Shift;
case Key.LWin:
case Key.RWin:
return ModifierKeys.Windows;
default:
return ModifierKeys.None;
}
}
private static bool IsModifierKey(Key key)
{
return key == Key.LeftCtrl || key == Key.LeftAlt || key == Key.LeftShift || key == Key.LWin ||
@@ -76,20 +76,14 @@ namespace HandyControl.Tools
else if (wParam == KeyUpIntPtr)
{
var virtualKey = Marshal.ReadInt32(lParam);
if (VirtualKey != virtualKey)
{
VirtualKey = virtualKey;
KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, false));
}
VirtualKey = -1;
KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, false));
}
else if (wParam == SyskeyUpIntPtr)
{
var virtualKey = Marshal.ReadInt32(lParam);
if (VirtualKey != virtualKey)
{
VirtualKey = virtualKey;
KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, true));
}
VirtualKey = -1;
KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, true));
}
}
return UnsafeNativeMethods.CallNextHookEx(HookId, nCode, wParam, lParam);