56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
// <copyright file="KeyboardInput.cs" company="PlaceholderCompany">
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
// </copyright>
|
|
|
|
using FSI.BT.Tools.TimeStampToClipboard.Helper;
|
|
using System;
|
|
|
|
namespace FSI.BT.Tools.TimeStampToClipboard.Handler
|
|
{
|
|
internal class KeyboardInput : IDisposable
|
|
{
|
|
|
|
private readonly KeyboardHook hook = new();
|
|
|
|
private int iRowKey = -1;
|
|
private int iMenuKey;
|
|
|
|
public KeyboardInput()
|
|
{
|
|
}
|
|
|
|
public event Action HotKeyPressed;
|
|
|
|
|
|
|
|
public void Dispose()
|
|
{
|
|
hook.KeyPressed -= Hook_KeyPressed;
|
|
hook.Dispose();
|
|
}
|
|
|
|
public void RegisterHotKey()
|
|
{
|
|
if (!string.IsNullOrEmpty(Global.Vars.TimeStampSettings.HotKey))
|
|
{
|
|
try
|
|
{
|
|
hook.RegisterHotKey();
|
|
hook.KeyPressed += Hook_KeyPressed;
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
//Log.Warn($"key:'{Properties.Settings.Default.HotKey}'", ex);
|
|
Global.Vars.TimeStampSettings.HotKey = string.Empty;
|
|
//Properties.Settings.Default.Save();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void Hook_KeyPressed(object sender, FSI.BT.Tools.TimeStampToClipboard.Helper.KeyPressedEventArgs e)
|
|
{
|
|
HotKeyPressed?.Invoke();
|
|
}
|
|
}
|
|
} |