// // Copyright (c) PlaceholderCompany. All rights reserved. // 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(); } } }