completed the branch
This commit is contained in:
1 parent
6e3171259e
commit
a269739949
4 files changed
+14
-49
No files matched your search
@@ -24,8 +24,8 @@
|
|||||||
d:DesignHeight="800"
|
d:DesignHeight="800"
|
||||||
d:DesignWidth="1400">
|
d:DesignWidth="1400">
|
||||||
<hc:GlobalShortcut.KeyBindings>
|
<hc:GlobalShortcut.KeyBindings>
|
||||||
<KeyBinding Modifiers="Control+Alt" Key="I" Command="{Binding GlobalShortcutInfoCmd}"/>
|
<KeyBinding Modifiers="Control+Alt" Key="I" Command="{Binding Main.GlobalShortcutInfoCmd, Source={StaticResource Locator}}"/>
|
||||||
<KeyBinding Modifiers="Control+Alt" Key="E" Command="{Binding GlobalShortcutErrorCmd}"/>
|
<KeyBinding Modifiers="Control+Alt" Key="E" Command="{Binding Main.GlobalShortcutWarningCmd, Source={StaticResource Locator}}"/>
|
||||||
</hc:GlobalShortcut.KeyBindings>
|
</hc:GlobalShortcut.KeyBindings>
|
||||||
<hc:Window.NonClientAreaContent>
|
<hc:Window.NonClientAreaContent>
|
||||||
<userControl:NoUserContent/>
|
<userControl:NoUserContent/>
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ namespace HandyControlDemo.ViewModel
|
|||||||
public RelayCommand GlobalShortcutInfoCmd => new Lazy<RelayCommand>(() =>
|
public RelayCommand GlobalShortcutInfoCmd => new Lazy<RelayCommand>(() =>
|
||||||
new RelayCommand(() => Growl.Info("Global Shortcut Info"))).Value;
|
new RelayCommand(() => Growl.Info("Global Shortcut Info"))).Value;
|
||||||
|
|
||||||
public RelayCommand GlobalShortcutErrorCmd => new Lazy<RelayCommand>(() =>
|
public RelayCommand GlobalShortcutWarningCmd => new Lazy<RelayCommand>(() =>
|
||||||
new RelayCommand(() => Growl.Info("Global Shortcut Error"))).Value;
|
new RelayCommand(() => Growl.Warning("Global Shortcut Warning"))).Value;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using HandyControl.Data;
|
using HandyControl.Data;
|
||||||
@@ -8,8 +7,6 @@ namespace HandyControl.Tools
|
|||||||
{
|
{
|
||||||
public class GlobalShortcut
|
public class GlobalShortcut
|
||||||
{
|
{
|
||||||
private static ModifierKeys ModifierKeys;
|
|
||||||
|
|
||||||
private static readonly Dictionary<string, KeyBinding> CommandDic = new Dictionary<string, KeyBinding>();
|
private static readonly Dictionary<string, KeyBinding> CommandDic = new Dictionary<string, KeyBinding>();
|
||||||
|
|
||||||
static GlobalShortcut()
|
static GlobalShortcut()
|
||||||
@@ -21,16 +18,11 @@ namespace HandyControl.Tools
|
|||||||
|
|
||||||
private static void HitTest(Key key)
|
private static void HitTest(Key key)
|
||||||
{
|
{
|
||||||
Console.WriteLine(key.ToString());
|
if (IsModifierKey(key)) return;
|
||||||
if (IsModifierKey(key))
|
|
||||||
{
|
var modifierKeys = Keyboard.Modifiers;
|
||||||
ModifierKeys |= GetModifierKey(key);
|
var keyStr = modifierKeys != ModifierKeys.None ? $"{modifierKeys.ToString()}, {key.ToString()}" : key.ToString();
|
||||||
}
|
ExecuteCommand(keyStr);
|
||||||
else
|
|
||||||
{
|
|
||||||
var keyStr = ModifierKeys != ModifierKeys.None ? $"{ModifierKeys.ToString()}, {key.ToString()}" : key.ToString();
|
|
||||||
ExecuteCommand(keyStr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ExecuteCommand(string key)
|
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)
|
private static bool IsModifierKey(Key key)
|
||||||
{
|
{
|
||||||
return key == Key.LeftCtrl || key == Key.LeftAlt || key == Key.LeftShift || key == Key.LWin ||
|
return key == Key.LeftCtrl || key == Key.LeftAlt || key == Key.LeftShift || key == Key.LWin ||
|
||||||
|
|||||||
@@ -76,20 +76,14 @@ namespace HandyControl.Tools
|
|||||||
else if (wParam == KeyUpIntPtr)
|
else if (wParam == KeyUpIntPtr)
|
||||||
{
|
{
|
||||||
var virtualKey = Marshal.ReadInt32(lParam);
|
var virtualKey = Marshal.ReadInt32(lParam);
|
||||||
if (VirtualKey != virtualKey)
|
VirtualKey = -1;
|
||||||
{
|
KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, false));
|
||||||
VirtualKey = virtualKey;
|
|
||||||
KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, false));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (wParam == SyskeyUpIntPtr)
|
else if (wParam == SyskeyUpIntPtr)
|
||||||
{
|
{
|
||||||
var virtualKey = Marshal.ReadInt32(lParam);
|
var virtualKey = Marshal.ReadInt32(lParam);
|
||||||
if (VirtualKey != virtualKey)
|
VirtualKey = -1;
|
||||||
{
|
KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, true));
|
||||||
VirtualKey = virtualKey;
|
|
||||||
KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return UnsafeNativeMethods.CallNextHookEx(HookId, nCode, wParam, lParam);
|
return UnsafeNativeMethods.CallNextHookEx(HookId, nCode, wParam, lParam);
|
||||||
|
|||||||
Reference in new issue
Block a user