Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionusing System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; namespace de { /// <summary> /// Description of MainForm. /// </summary> public partial class MainForm : Form { public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // } public enum HookType : int { 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 } [DllImport("user32.dll")] static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc callback, IntPtr hInstance, uint threadId); [DllImport("user32.dll")] static extern bool UnhookWindowsHookEx(IntPtr hInstance); [DllImport("user32.dll")] static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, int wParam, IntPtr lParam); [DllImport("kernel32.dll")] static extern IntPtr LoadLibrary(string lpFileName); private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam); const int WH_KEYBOARD_LL =13; const int WH_MOUSE_LL =14; const int WH_CBT =5; // ????? ??????????? LowLevel-???? ?? ?????????? const int WM_KEYDOWN = 0x100; // ????????? ??????? ??????? const int WM_COPY = 0x0301; const int WM_LBUTTONDBLCLK = 0x0204; private LowLevelKeyboardProc _proc = hookProc; private static IntPtr hhook = IntPtr.Zero; public void SetHook() { IntPtr hInstance = LoadLibrary("User32"); hhook = SetWindowsHookEx(WH_MOUSE_LL, _proc, hInstance, 0); } public static void UnHook() { UnhookWindowsHookEx(hhook); } public static IntPtr hookProc(int code, IntPtr wParam, IntPtr lParam) { if (code >= 0 && wParam == (IntPtr)WM_LBUTTONDBLCLK ) { MessageBox.Show(wParam.ToString()); return (IntPtr)1; } else return CallNextHookEx(hhook, code, (int)wParam, lParam); } void Button2Click(object sender, EventArgs e) { } void MainFormLoad(object sender, EventArgs e) { SetHook(); } void MainFormFormClosing(object sender, FormClosingEventArgs e) { UnHook(); } } }