📄 hook.cs
字号:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace gowk.common
{
public class HookEventArgs : EventArgs
{
int m_nCode;
IntPtr m_wParam;
IntPtr m_lParam;
public HookEventArgs(int nCode, IntPtr wParam, IntPtr lParam):base(){this.m_lParam=lParam;this.m_nCode=nCode;this.m_wParam=wParam;}
public int nCode{get{return this.m_nCode;}}
public IntPtr wParam{get{return this.m_wParam;}}
public IntPtr lParam{get{return this.m_lParam;}}
}
public delegate void HookEventHandler(object sender, HookEventArgs e);
public enum HookType
{
WH_JOURNALRECORD = 0,
WH_JOURNALPLAYBACK = 1,
WH_KEYBOARD = 2,
WH_GETMESSAGE = 3,
WH_CALLWNDPROC = 4,
WH_CBT = 5,
WH_SYSMSGFILTER = 6,
WH_MOUSE = 7,
WH_HARDWARE = 8,
WH_DEBUG = 9,
WH_SHELL = 10,
WH_FOREGROUNDIDLE = 11,
WH_CALLWNDPROCRET = 12,
WH_KEYBOARD_LL = 13,
WH_MOUSE_LL = 14
}
public class Hooker
{
private delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);
IntPtr m_hhook;
HookProc m_cb = null;
HookType m_ht;
public event HookEventHandler HookEvent;
public Hooker(HookType type)
{
this.m_ht=type;
this.m_cb=new HookProc(this.CallBack);
}
public HookType HookType{get{return this.m_ht;}}
protected int CallBack(int code, IntPtr wParam, IntPtr lParam)
{
if (code < 0)return CallNextHookEx(m_hhook, code, wParam, lParam);
if(this.HookEvent!=null)this.HookEvent(this,new HookEventArgs(code,wParam,lParam));
return CallNextHookEx(m_hhook, code, wParam, lParam);
}
public void Install()
{
m_hhook = SetWindowsHookEx(m_ht,m_cb,IntPtr.Zero,AppDomain.GetCurrentThreadId());
}
public void Uninstall()
{
UnhookWindowsHookEx(m_hhook);
}
#region
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
static extern IntPtr SetWindowsHookEx(HookType idHook,HookProc lpfn,IntPtr hMod,int dwThreadId);
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
static extern int CallNextHookEx(IntPtr hhk,int nCode,IntPtr wParam,IntPtr lParam);
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -