2021-12-10 17:58:23 +08:00
|
|
|
|
using GeekDesk.Control.UserControls.Config;
|
2022-07-25 17:57:57 +08:00
|
|
|
|
using GeekDesk.Control.Windows;
|
|
|
|
|
|
using GeekDesk.Util;
|
2021-12-10 17:58:23 +08:00
|
|
|
|
using GeekDesk.ViewModel;
|
|
|
|
|
|
using Gma.System.MouseKeyHook;
|
|
|
|
|
|
using System;
|
2022-07-25 17:57:57 +08:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Threading;
|
2021-12-10 17:58:23 +08:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
|
|
2022-03-25 16:23:14 +08:00
|
|
|
|
namespace GeekDesk.MyThread
|
2021-12-10 17:58:23 +08:00
|
|
|
|
{
|
|
|
|
|
|
public class MouseHookThread
|
|
|
|
|
|
{
|
|
|
|
|
|
private static AppConfig appConfig = MainWindow.appData.AppConfig;
|
2022-07-25 17:57:57 +08:00
|
|
|
|
private static IKeyboardMouseEvents middleHook = null;
|
|
|
|
|
|
private static Dispatcher middleDP;
|
2021-12-10 17:58:23 +08:00
|
|
|
|
|
|
|
|
|
|
public static void MiddleHook()
|
|
|
|
|
|
{
|
|
|
|
|
|
//使用dispatcher来单独监听UI线程 防止程序卡顿
|
2022-07-25 17:57:57 +08:00
|
|
|
|
middleDP = DispatcherBuild.Build();
|
|
|
|
|
|
middleHook = Hook.GlobalEvents();
|
|
|
|
|
|
middleDP.Invoke((Action)(() =>
|
2021-12-10 17:58:23 +08:00
|
|
|
|
{
|
2022-07-25 17:57:57 +08:00
|
|
|
|
middleHook.MouseUpExt += MiddleHookFun;
|
2021-12-10 17:58:23 +08:00
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-25 17:57:57 +08:00
|
|
|
|
|
|
|
|
|
|
private static Color GetBottomBeforeColor()
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetColor(1760, 985);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Color GetTopBeforeColor()
|
2021-12-13 13:03:50 +08:00
|
|
|
|
{
|
2022-07-25 17:57:57 +08:00
|
|
|
|
return GetColor(1751, 693);
|
2021-12-13 13:03:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-25 17:57:57 +08:00
|
|
|
|
private static Color GetColor(int w2, int h2)
|
|
|
|
|
|
{
|
|
|
|
|
|
double w = 1920;
|
|
|
|
|
|
double h = 1080;
|
|
|
|
|
|
double width = SystemParameters.PrimaryScreenWidth;
|
|
|
|
|
|
double height = SystemParameters.PrimaryScreenHeight;
|
|
|
|
|
|
System.Drawing.Point p = new System.Drawing.Point((int)(w2 / w * width), (int)(h2 / h * height));
|
|
|
|
|
|
return ScreenUtil.GetColorAt(p);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-10 17:58:23 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 鼠标中键呼出
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
2022-07-25 17:57:57 +08:00
|
|
|
|
private static void MiddleHookFun(object sender, System.Windows.Forms.MouseEventArgs e)
|
2021-12-10 17:58:23 +08:00
|
|
|
|
{
|
2022-07-25 17:57:57 +08:00
|
|
|
|
if (e.Button == System.Windows.Forms.MouseButtons.Middle)
|
2021-12-10 17:58:23 +08:00
|
|
|
|
{
|
2022-07-25 17:57:57 +08:00
|
|
|
|
//中键打开App
|
|
|
|
|
|
if (appConfig.MouseMiddleShow)
|
2021-12-10 17:58:23 +08:00
|
|
|
|
{
|
2022-07-25 17:57:57 +08:00
|
|
|
|
if (MotionControl.hotkeyFinished)
|
2022-05-20 15:39:52 +08:00
|
|
|
|
{
|
2022-07-25 17:57:57 +08:00
|
|
|
|
App.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render, new Action(() =>
|
2021-12-10 17:58:23 +08:00
|
|
|
|
{
|
2022-07-25 17:57:57 +08:00
|
|
|
|
if (MainWindow.mainWindow.Visibility == Visibility.Collapsed || MainWindow.mainWindow.Opacity == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
MainWindow.ShowApp();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
MainWindow.HideApp();
|
|
|
|
|
|
}
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
2021-12-10 17:58:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-25 17:57:57 +08:00
|
|
|
|
|
|
|
|
|
|
public static void DisposeMiddle()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (middleHook != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
middleHook.MouseUpExt -= MiddleHookFun;
|
|
|
|
|
|
middleHook.Dispose();
|
|
|
|
|
|
middleDP.InvokeShutdown();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex) { }
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-10 17:58:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|