• 大小: 64KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: C/C++
  • 标签: C#  全局HOO  Global  Hook  

资源简介

C#实现键盘鼠标全局钩子 VS2013,可编译运行,带DEMO 可全局拦截鼠标单击/双击/滚动事件 可全局拦截键盘按键事件 可锁定键盘鼠标输入,比如锁屏! 该代码无法屏蔽Ctrl +alt +delete 需要实现所有拦截,请参考相关C++实现

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;

namespace AdrHook
{
    /// 
    /// 功能说明:该组件监视所有的鼠标活动在全局范围(同时也是应用程序之外)
    /// 开发人员:王旭(http://www.wxzzz.com)
    /// 开发时间:2014年4月3日
    /// 

    public class GlobalEventProvider : Component
    {
        /// 
        /// 该组件引发事件。该值始终为true
        /// 

        protected override bool CanRaiseEvents
        {
            get
            {
                return true;
            }
        }

        #region 鼠标事件

        private event MouseEventHandler m_MouseMove;

        /// 
        /// 当鼠标指针移动时发生
        /// 

        public event MouseEventHandler MouseMove
        {
            add
            {
                if (m_MouseMove == null)
                {
                    HookManager.MouseMove += HookManager_MouseMove;
                }
                m_MouseMove += value;
            }

            remove
            {
                m_MouseMove -= value;
                if (m_MouseMove == null)
                {
                    HookManager.MouseMove -= HookManager_MouseMove;
                }
            }
        }

        void HookManager_MouseMove(object sender MouseEventArgs e)
        {
            if (m_MouseMove != null)
            {
                m_MouseMove.Invoke(this e);
            }
        }

        private event MouseEventHandler m_MouseClick;
        /// 
        /// 当点击由鼠标完成时发生
        /// 

        public event MouseEventHandler MouseClick
        {
            add
            {
                if (m_MouseClick == null)
                {
                    HookManager.MouseClick += HookManager_MouseClick;
                }
                m_MouseClick += value;
            }

            remove
            {
                m_MouseClick -= value;
                if (m_MouseClick == null)
                {
                    HookManager.MouseClick -= HookManager_MouseClick;
                }
            }
        }

        void HookManager_MouseClick(object sender MouseEventArgs e)
        {
            if (m_MouseClick != null)
            {
                m_MouseClick.Invoke(this e);
            }
        }

        private event MouseEventHandler m_MouseDown;

        /// 
        /// 当鼠标按下鼠标按钮时发生
        /// 

        public event MouseEventHandler MouseDown
        {
            add
            {
                if (m_MouseDown == null)
                {
                    HookManager.MouseDown += HookManager_MouseDown;
                }
                m_MouseDown += value;
            }

            remove
            {
                m_MouseDown -= value;
                if (m_MouseDown == null)
                {
                    HookManager.MouseDown -= HookMana

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2631  2014-04-03 11:23  codesc.net\AdrHookDemo\AdrHook\AdrHook.csproj

     文件      19456  2014-04-03 12:45  codesc.net\AdrHookDemo\AdrHook\bin\Debug\AdrHook.dll

     文件      42496  2014-04-03 12:45  codesc.net\AdrHookDemo\AdrHook\bin\Debug\AdrHook.pdb

     文件       9960  2014-04-03 12:45  codesc.net\AdrHookDemo\AdrHook\GlobalEventProvider.cs

     文件      14120  2014-04-03 12:44  codesc.net\AdrHookDemo\AdrHook\HookManager.Callback.cs

     文件      10308  2014-04-03 11:40  codesc.net\AdrHookDemo\AdrHook\HookManager.cs

     文件       3038  2014-04-03 12:44  codesc.net\AdrHookDemo\AdrHook\HookManager.Structures.cs

     文件       5629  2014-04-03 12:44  codesc.net\AdrHookDemo\AdrHook\HookManager.Windows.cs

     文件       1264  2014-04-03 12:44  codesc.net\AdrHookDemo\AdrHook\MouseEventExtArgs.cs

     文件        623  2014-04-03 12:45  codesc.net\AdrHookDemo\AdrHook\obj\Debug\AdrHook.csproj.FileListAbsolute.txt

     文件      19456  2014-04-03 12:45  codesc.net\AdrHookDemo\AdrHook\obj\Debug\AdrHook.dll

     文件      42496  2014-04-03 12:45  codesc.net\AdrHookDemo\AdrHook\obj\Debug\AdrHook.pdb

     文件       5821  2014-04-03 12:35  codesc.net\AdrHookDemo\AdrHook\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1338  2014-04-03 11:09  codesc.net\AdrHookDemo\AdrHook\Properties\AssemblyInfo.cs

     文件       3764  2014-04-03 12:39  codesc.net\AdrHookDemo\AdrHookDemo\AdrHookDemo.csproj

     文件      19456  2014-04-03 12:45  codesc.net\AdrHookDemo\AdrHookDemo\bin\Debug\AdrHook.dll

     文件       5883  2014-04-03 12:45  codesc.net\AdrHookDemo\AdrHookDemo\FrmMain.cs

     文件      12775  2014-04-03 12:39  codesc.net\AdrHookDemo\AdrHookDemo\FrmMain.Designer.cs

     文件       5817  2014-04-03 12:39  codesc.net\AdrHookDemo\AdrHookDemo\FrmMain.resx

     文件        474  2014-04-03 12:35  codesc.net\AdrHookDemo\AdrHookDemo\Program.cs

     文件       1346  2014-04-03 12:34  codesc.net\AdrHookDemo\AdrHookDemo\Properties\AssemblyInfo.cs

     文件       2874  2014-04-03 12:34  codesc.net\AdrHookDemo\AdrHookDemo\Properties\Resources.Designer.cs

     文件       5612  2014-04-03 12:34  codesc.net\AdrHookDemo\AdrHookDemo\Properties\Resources.resx

     文件       1098  2014-04-03 12:34  codesc.net\AdrHookDemo\AdrHookDemo\Properties\Settings.Designer.cs

     文件        249  2014-04-03 12:34  codesc.net\AdrHookDemo\AdrHookDemo\Properties\Settings.settings

     文件       1477  2014-04-03 12:39  codesc.net\AdrHookDemo\AdrHookDemo.sln

    ..A..H.     27136  2014-04-03 12:39  codesc.net\AdrHookDemo\AdrHookDemo.v12.suo

     文件        178  2018-07-28 10:01  codesc.net\AdrHookDemo\说明.txt

     目录          0  2014-04-03 11:09  codesc.net\AdrHookDemo\AdrHook\obj\Debug\TempPE

     目录          0  2018-07-28 10:00  codesc.net\AdrHookDemo\AdrHook\bin\Debug

............此处省略16个文件信息

评论

共有 条评论