Files
FSI.BT.IR.Tools/FSI.BT.Tools/RadialMenu/Buisness/KeyboardInput.cs
Maier Stephan SI 1c68b8f401 Sicherung
2023-04-17 07:07:49 +02:00

59 lines
1.4 KiB
C#

// <copyright file="KeyboardInput.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace FSI.BT.Tools.RadialMenu.Handler
{
using FSI.BT.Tools.RadialMenu.Helper;
using System;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
internal class KeyboardInput : IDisposable
{
private readonly KeyboardHook hook = new();
public KeyboardInput()
{
}
public event Action HotKeyPressed;
public void Dispose()
{
hook.KeyPressed -= Hook_KeyPressed;
hook.Dispose();
}
public void RegisterHotKey()
{
if (!string.IsNullOrEmpty(Global.Vars.RadialMenuSettings.HotKey))
{
try
{
hook.RegisterHotKey();
hook.KeyPressed += Hook_KeyPressed;
}
catch (InvalidOperationException ex)
{
//Log.Warn($"key:'{Properties.Settings.Default.HotKey}'", ex);
Global.Vars.RadialMenuSettings.HotKey = string.Empty;
//Properties.Settings.Default.Save();
}
}
}
private void Hook_KeyPressed(object sender, KeyPressedEventArgs e)
{
HotKeyPressed?.Invoke();
}
}
}