Files
GeekDesk/Control/UserControls/MotionControl.xaml.cs

77 lines
2.3 KiB
C#
Raw Normal View History

2021-05-31 17:31:16 +08:00
using GeekDesk.Util;
using GeekDesk.ViewModel;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace GeekDesk.Control.UserControls
{
/// <summary>
/// 动作设置
/// </summary>
public partial class MotionControl : UserControl
{
2021-05-31 21:54:10 +08:00
private static bool controlKeyDown = false;
private static AppConfig appConfig = MainWindow.appData.AppConfig;
2021-05-31 17:31:16 +08:00
public MotionControl()
{
InitializeComponent();
}
2021-05-31 21:54:10 +08:00
/// <summary>
/// 热键按下
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void HotKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control)
|| e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Windows)
|| e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Alt)
|| (e.Key >= Key.A && e.Key <= Key.Z))
{
if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control)
|| e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Windows)
|| e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Alt))
{
2021-06-01 17:31:05 +08:00
appConfig.HotkeyStr += GetKeyName(e);
} else if (appConfig.HotkeyStr.Length > 0
2021-05-31 21:54:10 +08:00
&& (e.Key >= Key.A && e.Key <= Key.Z))
{
appConfig.HotkeyStr += e.Key.ToString();
}
}
2021-05-31 17:31:16 +08:00
}
2021-06-01 17:31:05 +08:00
private string GetKeyName(KeyEventArgs e)
{
if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control))
{
return "Ctrl + ";
} else if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Windows))
{
return "Win + ";
} else if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Alt))
{
return "Alt + ";
}
return "";
}
2021-05-31 17:31:16 +08:00
}
}