You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.6 KiB
C#
70 lines
1.6 KiB
C#
using Gma.System.MouseKeyHook;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace POSV.Utils
|
|
{
|
|
public class KeyboardUtils
|
|
{
|
|
private Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
private IKeyboardMouseEvents _events;
|
|
|
|
private static object _lock = new object();
|
|
|
|
private static KeyboardUtils _instance = null;
|
|
|
|
private KeyboardUtils()
|
|
{
|
|
this._events = Hook.AppEvents();
|
|
}
|
|
|
|
public static KeyboardUtils Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
lock (_lock)
|
|
{
|
|
_instance = new KeyboardUtils();
|
|
}
|
|
}
|
|
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
public void RegisterHook(KeyEventHandler appHookKeyDown)
|
|
{
|
|
this.RegisterHook(appHookKeyDown,"注册键盘事件");
|
|
}
|
|
|
|
public void RegisterHook(KeyEventHandler appHookKeyDown,string message)
|
|
{
|
|
this._events.KeyDown += appHookKeyDown;
|
|
|
|
logger.Debug(message);
|
|
}
|
|
|
|
|
|
public void UnRegisterHook(KeyEventHandler appHookKeyDown)
|
|
{
|
|
this.UnRegisterHook(appHookKeyDown , "卸载键盘事件");
|
|
}
|
|
|
|
public void UnRegisterHook(KeyEventHandler appHookKeyDown , string message)
|
|
{
|
|
this._events.KeyDown -= appHookKeyDown;
|
|
|
|
logger.Debug(message);
|
|
}
|
|
|
|
|
|
}
|
|
}
|