Skip to main content
 首页 » 编程设计

c#之我如何全局 Hook 所有键和所有鼠标按钮

2024年02月13日7JustinYoung

<分区>

我在 Form1 上衣做了 :

using Gma.UserActivityMonitor; 

然后声明:

Gma.UserActivityMonitor.GlobalEventProvider actHook = new GlobalEventProvider(); 

然后在 Load 事件中我做了:

actHook.MouseClick += actHook_MouseClick; 

然后在底部:

private void actHook_MouseClick(object sender, MouseEventArgs e) 
        { 
            if (e.Clicks > 0) 
            { 
                MessageBox.Show("hi"); 
            } 
        } 

但是一旦我在加载任何内容之前一秒后运行我的应用程序,我就会在文件上遇到异常:HookManager.Callbacks.cs

在线:

throw new Win32Exception(errorCode); 

异常:找不到指定的模块

System.ComponentModel.Win32Exception was unhandled 
  HResult=-2147467259 
  Message=The specified module could not be found 
  Source=ScreenVideoRecorder 
  ErrorCode=-2147467259 
  NativeErrorCode=126 
  StackTrace: 
       at Gma.UserActivityMonitor.HookManager.EnsureSubscribedToGlobalMouseEvents() in d:\C-Sharp\ScreenVideoRecorder\ScreenVideoRecorderWorkingVersion\HookManager.Callbacks.cs:line 236 
       at Gma.UserActivityMonitor.HookManager.add_MouseClick(MouseEventHandler value) in d:\C-Sharp\ScreenVideoRecorder\ScreenVideoRecorderWorkingVersion\HookManager.cs:line 69 
       at Gma.UserActivityMonitor.GlobalEventProvider.add_MouseClick(MouseEventHandler value) in d:\C-Sharp\ScreenVideoRecorder\ScreenVideoRecorderWorkingVersion\GlobalEventProvider.cs:line 71 
       at ScreenVideoRecorder.Form1.Form1_Load(Object sender, EventArgs e) in d:\C-Sharp\ScreenVideoRecorder\ScreenVideoRecorderWorkingVersion\Form1.cs:line 47 
       at System.Windows.Forms.Form.OnLoad(EventArgs e) 
       at System.Windows.Forms.Form.OnCreateControl() 
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 
       at System.Windows.Forms.Control.CreateControl() 
       at System.Windows.Forms.Control.WmShowWindow(Message& m) 
       at System.Windows.Forms.Control.WndProc(Message& m) 
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m) 
       at System.Windows.Forms.ContainerControl.WndProc(Message& m) 
       at System.Windows.Forms.Form.WmShowWindow(Message& m) 
       at System.Windows.Forms.Form.WndProc(Message& m) 
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
  InnerException:  

找不到什么或哪​​个模块?

我下载了版本2的源代码。 并添加了硬盘上 : Gma.UserActivityMonitor 目录中的所有文件 .cs。

我没有收到丢失某些东西的错误消息,那会是什么?