zoukankan      html  css  js  c++  java
  • 添加钩子 Hook

    using System;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    using Lsj.Util.Win32;
    using Lsj.Util.Win32.BaseTypes;
    using Lsj.Util.Win32.Enums;
    
    private readonly User32.HOOKPROC _mouseHook;
    private IntPtr _hMouseHook;
    public void AddHook()
    {
        Console.WriteLine("添加钩子……");
        var hModule = Kernel32.GetModuleHandle(null);
        _hMouseHook = User32.SetWindowsHookEx(
            (int)WindowHookTypes.WH_MOUSE_LL,
            _mouseHook,
            hModule,
            0);
        if (_hMouseHook == IntPtr.Zero)
        {
            int errorCode = Marshal.GetLastWin32Error();
            Console.WriteLine($"添加钩子发生错误 {errorCode}");
            throw new Win32Exception(errorCode);
        }
        Console.WriteLine("添加钩子完成。");
    }
    
    private LRESULT OnMouseHook(int code, WPARAM wParam, LPARAM lParam)
    {
        return User32.CallNextHookEx(new IntPtr(0), code, wParam, lParam);
    }
    
  • 相关阅读:
    函数和递归
    对象
    数组
    For...In 声明
    JavaScript 变量的生存期
    Hadoop Hive与Hbase整合+thrift
    朱子治家格言
    大学
    《孙子兵法》【谋攻第三】
    棋经十三篇
  • 原文地址:https://www.cnblogs.com/wesson2019-blog/p/13686955.html
Copyright © 2011-2022 走看看