|
@@ -7,6 +7,7 @@ using Microsoft.Win32;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Runtime.CompilerServices;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
@@ -27,8 +28,9 @@ namespace GeekDesk.Control.UserControls.Config
|
|
|
/// </summary>
|
|
|
public partial class MotionControl : UserControl
|
|
|
{
|
|
|
- private static bool hotkeyFinished = true; //热键设置结束
|
|
|
+ public static bool hotkeyFinished = true; //热键设置结束
|
|
|
private static KeyEventArgs prevKeyTemp; //上一个按键
|
|
|
+ private static List<KeyEventArgs> keysTemp = new List<KeyEventArgs>();//存储一次快捷键集合
|
|
|
private static AppConfig appConfig = MainWindow.appData.AppConfig;
|
|
|
|
|
|
public MotionControl()
|
|
@@ -62,6 +64,7 @@ namespace GeekDesk.Control.UserControls.Config
|
|
|
appConfig.HotkeyStr = GetKeyName(e);
|
|
|
appConfig.HotkeyModifiers = GetModifierKeys(e);
|
|
|
prevKeyTemp = e;
|
|
|
+ keysTemp.Add(e);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -75,12 +78,14 @@ namespace GeekDesk.Control.UserControls.Config
|
|
|
appConfig.Hotkey = e.Key;
|
|
|
appConfig.HotkeyStr += e.Key.ToString();
|
|
|
prevKeyTemp = e;
|
|
|
+ keysTemp.Add(e);
|
|
|
}
|
|
|
else if (CheckModifierKeys(e))
|
|
|
{
|
|
|
appConfig.HotkeyStr += GetKeyName(e);
|
|
|
appConfig.HotkeyModifiers |= GetModifierKeys(e);
|
|
|
prevKeyTemp = e;
|
|
|
+ keysTemp.Add(e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -138,94 +143,94 @@ namespace GeekDesk.Control.UserControls.Config
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void HotKeyUp(object sender, KeyEventArgs e)
|
|
|
+ [MethodImpl(MethodImplOptions.Synchronized)]
|
|
|
+ private void HotKeyUp(object sender, KeyEventArgs e)
|
|
|
{
|
|
|
- hotkeyFinished = true;
|
|
|
- ConfigWindow cw = (ConfigWindow)Window.GetWindow(this);
|
|
|
- try
|
|
|
+ lock(this)
|
|
|
{
|
|
|
- if (cw.mainWindow.hotKeyId != -1)
|
|
|
+ bool allKeyUp = true;
|
|
|
+ //判断所有键是否都松开
|
|
|
+ foreach (KeyEventArgs key in keysTemp)
|
|
|
{
|
|
|
- Hotkey.UnRegist(new WindowInteropHelper(cw.mainWindow).Handle, Hotkey.keymap[cw.mainWindow.hotKeyId]);
|
|
|
- }
|
|
|
- cw.mainWindow.hotKeyId = Hotkey.Regist(cw.mainWindow, appConfig.HotkeyModifiers, appConfig.Hotkey, () =>
|
|
|
- {
|
|
|
- if (cw.mainWindow.Visibility == Visibility.Collapsed)
|
|
|
+ HandyControl.Controls.Growl.SuccessGlobal(key.Key.ToString() + "=" + key.KeyStates);
|
|
|
+ if (key.KeyStates == KeyStates.Down)
|
|
|
{
|
|
|
- cw.mainWindow.ShowApp();
|
|
|
+ allKeyUp = false;
|
|
|
+ break;
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ if (allKeyUp && !hotkeyFinished)
|
|
|
+ {
|
|
|
+ hotkeyFinished = true;
|
|
|
+ if (MainWindow.hotKeyId != -1)
|
|
|
{
|
|
|
- cw.mainWindow.Visibility = Visibility.Collapsed;
|
|
|
+ Hotkey.UnRegist(new WindowInteropHelper(MainWindow.mainWindow).Handle, Hotkey.keymap[MainWindow.hotKeyId]);
|
|
|
}
|
|
|
- });
|
|
|
- } catch (Exception)
|
|
|
- {
|
|
|
- HandyControl.Controls.Growl.WarningGlobal("当前快捷键已被其它程序占用(" + appConfig.HotkeyStr + ")!");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private void ShowApp(MainWindow mainWindow)
|
|
|
- {
|
|
|
- if (appConfig.FollowMouse)
|
|
|
- {
|
|
|
- ShowAppAndFollowMouse(mainWindow);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- this.Visibility = Visibility.Visible;
|
|
|
+ MainWindow.RegisterHotKey();
|
|
|
+ }
|
|
|
}
|
|
|
- Keyboard.Focus(this);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 随鼠标位置显示面板 (鼠标始终在中间)
|
|
|
- /// </summary>
|
|
|
- private void ShowAppAndFollowMouse(MainWindow mainWindow)
|
|
|
- {
|
|
|
- //获取鼠标位置
|
|
|
- System.Windows.Point p = MouseUtil.GetMousePosition();
|
|
|
- double left = SystemParameters.VirtualScreenLeft;
|
|
|
- double top = SystemParameters.VirtualScreenTop;
|
|
|
- double width = SystemParameters.VirtualScreenWidth;
|
|
|
- double height = SystemParameters.VirtualScreenHeight;
|
|
|
- double right = width - Math.Abs(left);
|
|
|
- double bottom = height - Math.Abs(top);
|
|
|
-
|
|
|
-
|
|
|
- if (p.X - mainWindow.Width / 2 < left)
|
|
|
- {
|
|
|
- //判断是否在最左边缘
|
|
|
- mainWindow.Left = left;
|
|
|
- }
|
|
|
- else if (p.X + mainWindow.Width / 2 > right)
|
|
|
- {
|
|
|
- //判断是否在最右边缘
|
|
|
- mainWindow.Left = right - mainWindow.Width;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- mainWindow.Left = p.X - mainWindow.Width / 2;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (p.Y - mainWindow.Height / 2 < top)
|
|
|
- {
|
|
|
- //判断是否在最上边缘
|
|
|
- mainWindow.Top = top;
|
|
|
- }
|
|
|
- else if (p.Y + mainWindow.Height / 2 > bottom)
|
|
|
- {
|
|
|
- //判断是否在最下边缘
|
|
|
- mainWindow.Top = bottom - mainWindow.Height;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- mainWindow.Top = p.Y - mainWindow.Height / 2;
|
|
|
- }
|
|
|
-
|
|
|
- mainWindow.Visibility = Visibility.Visible;
|
|
|
- }
|
|
|
+ //private void ShowApp(MainWindow mainWindow)
|
|
|
+ //{
|
|
|
+ // if (appConfig.FollowMouse)
|
|
|
+ // {
|
|
|
+ // ShowAppAndFollowMouse(mainWindow);
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // this.Visibility = Visibility.Visible;
|
|
|
+ // }
|
|
|
+ // Keyboard.Focus(this);
|
|
|
+ //}
|
|
|
+
|
|
|
+ ///// <summary>
|
|
|
+ ///// 随鼠标位置显示面板 (鼠标始终在中间)
|
|
|
+ ///// </summary>
|
|
|
+ //private void ShowAppAndFollowMouse(MainWindow mainWindow)
|
|
|
+ //{
|
|
|
+ // //获取鼠标位置
|
|
|
+ // System.Windows.Point p = MouseUtil.GetMousePosition();
|
|
|
+ // double left = SystemParameters.VirtualScreenLeft;
|
|
|
+ // double top = SystemParameters.VirtualScreenTop;
|
|
|
+ // double width = SystemParameters.VirtualScreenWidth;
|
|
|
+ // double height = SystemParameters.VirtualScreenHeight;
|
|
|
+ // double right = width - Math.Abs(left);
|
|
|
+ // double bottom = height - Math.Abs(top);
|
|
|
+
|
|
|
+
|
|
|
+ // if (p.X - mainWindow.Width / 2 < left)
|
|
|
+ // {
|
|
|
+ // //判断是否在最左边缘
|
|
|
+ // mainWindow.Left = left;
|
|
|
+ // }
|
|
|
+ // else if (p.X + mainWindow.Width / 2 > right)
|
|
|
+ // {
|
|
|
+ // //判断是否在最右边缘
|
|
|
+ // mainWindow.Left = right - mainWindow.Width;
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // mainWindow.Left = p.X - mainWindow.Width / 2;
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+ // if (p.Y - mainWindow.Height / 2 < top)
|
|
|
+ // {
|
|
|
+ // //判断是否在最上边缘
|
|
|
+ // mainWindow.Top = top;
|
|
|
+ // }
|
|
|
+ // else if (p.Y + mainWindow.Height / 2 > bottom)
|
|
|
+ // {
|
|
|
+ // //判断是否在最下边缘
|
|
|
+ // mainWindow.Top = bottom - mainWindow.Height;
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // mainWindow.Top = p.Y - mainWindow.Height / 2;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // mainWindow.Visibility = Visibility.Visible;
|
|
|
+ //}
|
|
|
}
|
|
|
}
|