下班, 最近要忙起来了
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using GeekDesk.Util;
|
||||
using GeekDesk.ViewModel;
|
||||
using GlobalHotKey;
|
||||
using HandyControl.Data;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,6 +13,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
@@ -140,11 +143,15 @@ namespace GeekDesk.Control.UserControls
|
||||
ConfigWindow cw = (ConfigWindow)Window.GetWindow(this);
|
||||
try
|
||||
{
|
||||
Hotkey.Regist(cw.mainWindow, appConfig.HotkeyModifiers, appConfig.Hotkey, () =>
|
||||
if (cw.mainWindow.hotKeyId != -1)
|
||||
{
|
||||
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)
|
||||
{
|
||||
ShowApp(cw.mainWindow);
|
||||
cw.mainWindow.ShowApp();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -153,7 +160,7 @@ namespace GeekDesk.Control.UserControls
|
||||
});
|
||||
} catch (Exception)
|
||||
{
|
||||
HandyControl.Controls.Growl.ErrorGlobal("热键注册失败,当前热键已被其它程序占用!");
|
||||
HandyControl.Controls.Growl.WarningGlobal("当前快捷键已被其它程序占用(" + appConfig.HotkeyStr + ")!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using GeekDesk.Control;
|
||||
using GeekDesk.Util;
|
||||
using GeekDesk.ViewModel;
|
||||
using GlobalHotKey;
|
||||
using HandyControl.Data;
|
||||
using SharpShell.SharpContextMenu;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -26,6 +27,8 @@ namespace GeekDesk
|
||||
{
|
||||
|
||||
public static AppData appData = CommonCode.GetAppDataByFile();
|
||||
public int hotKeyId = -1;
|
||||
public HotKeyManager hkm = new HotKeyManager();
|
||||
public MainWindow()
|
||||
{
|
||||
LoadData();
|
||||
@@ -53,19 +56,46 @@ namespace GeekDesk
|
||||
{
|
||||
this.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
//加载完毕注册热键
|
||||
Hotkey.Regist(this, HotkeyModifiers.MOD_CONTROL | HotkeyModifiers.MOD_ALT, Key.Y, ()=>
|
||||
try
|
||||
{
|
||||
HotKey hk = hkm.Register(Key.Y, ModifierKeys.Control);
|
||||
hkm.KeyPressed += DisplayWindowHotKeyPress;
|
||||
////加载完毕注册热键
|
||||
//hotKeyId = Hotkey.Regist(this, appData.AppConfig.HotkeyModifiers, appData.AppConfig.Hotkey, () =>
|
||||
//{
|
||||
// if (this.Visibility == Visibility.Collapsed)
|
||||
// {
|
||||
// ShowApp();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.Visibility = Visibility.Collapsed;
|
||||
// }
|
||||
//});
|
||||
} catch (Exception)
|
||||
{
|
||||
HandyControl.Controls.Growl.WarningGlobal("启动快捷键已被其它程序占用(" + appData.AppConfig.HotkeyStr + ")!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DisplayWindowHotKeyPress(object sender, KeyPressedEventArgs e)
|
||||
{
|
||||
if (e.HotKey.Key == Key.Y)
|
||||
{
|
||||
if (this.Visibility == Visibility.Collapsed)
|
||||
{
|
||||
ShowApp();
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainWindow_Resize(object sender, System.EventArgs e)
|
||||
{
|
||||
@@ -148,7 +178,7 @@ namespace GeekDesk
|
||||
{
|
||||
ShowApp();
|
||||
}
|
||||
private void ShowApp()
|
||||
public void ShowApp()
|
||||
{
|
||||
if (appData.AppConfig.FollowMouse)
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace GeekDesk.Util
|
||||
/// <param name="fsModifiers">组合键</param>
|
||||
/// <param name="key">快捷键</param>
|
||||
/// <param name="callBack">回调函数</param>
|
||||
public static bool Regist(Window window, HotkeyModifiers fsModifiers, Key key, HotKeyCallBackHanlder callBack)
|
||||
public static int Regist(Window window, HotkeyModifiers fsModifiers, Key key, HotKeyCallBackHanlder callBack)
|
||||
{
|
||||
var hwnd = new WindowInteropHelper(window).Handle;
|
||||
var _hwndSource = HwndSource.FromHwnd(hwnd);
|
||||
@@ -40,8 +40,8 @@ namespace GeekDesk.Util
|
||||
|
||||
var vk = KeyInterop.VirtualKeyFromKey(key);
|
||||
keymap[id] = callBack;
|
||||
|
||||
return RegisterHotKey(hwnd, id, fsModifiers, (uint)vk);
|
||||
if (!RegisterHotKey(hwnd, id, fsModifiers, (uint)vk)) throw new Exception("RegisterHotKey Failed");
|
||||
return id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -77,7 +77,7 @@ namespace GeekDesk.Util
|
||||
|
||||
const int WM_HOTKEY = 0x312;
|
||||
static int keyid = 10;
|
||||
static Dictionary<int, HotKeyCallBackHanlder> keymap = new Dictionary<int, HotKeyCallBackHanlder>();
|
||||
public static Dictionary<int, HotKeyCallBackHanlder> keymap = new Dictionary<int, HotKeyCallBackHanlder>();
|
||||
|
||||
public delegate void HotKeyCallBackHanlder();
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ namespace GeekDesk.ViewModel
|
||||
private int pannelCornerRadius = 4; //面板圆角 默认4
|
||||
[field: NonSerialized]
|
||||
private ObservableCollection<IconInfo> selectedMenuIcons;
|
||||
private string hotkeyStr;
|
||||
private HotkeyModifiers hotkeyModifiers;
|
||||
private Key hotkey;
|
||||
private string hotkeyStr = "Ctrl + Q";
|
||||
private HotkeyModifiers hotkeyModifiers = HotkeyModifiers.MOD_CONTROL;
|
||||
private Key hotkey = Key.Q;
|
||||
|
||||
#region GetSet
|
||||
public Key Hotkey
|
||||
|
||||
Reference in New Issue
Block a user