以下代码供参考,关于HOOK
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Reflection;
public enum HookType
{
WH_KEYBOARD = 2
}
//IntPtr
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
//Declare hook handle as int.
static int hKeyboardHook = 0;
HookProc KeyboardHookProcedure;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
///
[DllImport("kernel32")]
public static extern int GetCurrentThreadId();
//Import for SetWindowsHookEx function.
//Use this function to install thread-specific hook.
[DllImport("user32.dll",CharSet=CharSet.Auto,
CallingConvention=CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn,
IntPtr hInstance, int threadId);
//Import for UnhookWindowsHookEx.
//Call this function to uninstall the hook.
[DllImport("user32.dll",CharSet=CharSet.Auto,
CallingConvention=CallingConvention.StdCall)]
public static extern bool UnhookWindowsHookEx(int idHook);
//Import for CallNextHookEx.
//Use this function to pass the hook information to next hook procedure in chain.
[DllImport("user32.dll",CharSet=CharSet.Auto,
CallingConvention=CallingConvention.StdCall)]
public static extern int CallNextHookEx(int idHook, int nCode,
IntPtr wParam, IntPtr lParam);
//线程注入
[DllImport("RunDLL.dll",CharSet=CharSet.Ansi,EntryPoint = "EnabledKey")]
public static extern Boolean EnabledKeys(string s);
[DllImport("RunDLL.dll",CharSet=CharSet.Ansi,EntryPoint = "DisabledKey")]
public static extern Boolean DisabledKeys(string s);