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.
|
|
|
|
using Gma.System.MouseKeyHook;
|
|
|
|
|
using NLog;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace JwKdsV.Core.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._events.KeyDown += appHookKeyDown;
|
|
|
|
|
logger.Info(">>>>注册键盘钩子成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegisterHook(KeyEventHandler appHookKeyDown, string message)
|
|
|
|
|
{
|
|
|
|
|
this._events.KeyDown += appHookKeyDown;
|
|
|
|
|
logger.Info(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void UnRegisterHook(KeyEventHandler appHookKeyDown)
|
|
|
|
|
{
|
|
|
|
|
this._events.KeyDown -= appHookKeyDown;
|
|
|
|
|
logger.Info(">>>>卸载键盘钩子成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UnRegisterHook(KeyEventHandler appHookKeyDown, string message)
|
|
|
|
|
{
|
|
|
|
|
this._events.KeyDown -= appHookKeyDown;
|
|
|
|
|
logger.Info(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|