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);
    }
    
  • 相关阅读:
    KVM快速构建虚拟机
    工程师测试
    配置SMB,NFS
    Shell脚本基础应用
    Web网页部署
    基础邮件,mariadb数据库
    SElinux,firewalld配置
    Linux管理员测试
    磁盘分区
    配置权限,LDAP
  • 原文地址:https://www.cnblogs.com/wesson2019-blog/p/13686955.html
Copyright © 2011-2022 走看看