1

我在我的 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。

我没有收到缺少某些东西的错误,那会是什么?

4

1 回答 1

4

我刚刚从GlobalMouseKeyHook CodePlex站点下载了文件并将其解压缩,然后将其添加到我的项目中。然后我在表单中添加了使用引用。我正在运行针对 .Net 4 客户端配置文件的 Visual Studio 2010 Pro。我没有问题MouseKeyboardActivityMonitor.dll

这是一个工作示例(此代码是从 GlobalMouseKeyHook 演示项目修改的:

using System;
using System.Collections.Generic;  
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MouseKeyboardActivityMonitor;
using MouseKeyboardActivityMonitor.WinApi;

namespace WindowsFormsApplication1
{

    public partial class Form1 : Form
    {
        private readonly KeyboardHookListener m_KeyboardHookManager;
        private readonly MouseHookListener m_MouseHookManager;
        public Form1()
        {
            InitializeComponent();
            m_KeyboardHookManager = new KeyboardHookListener(new GlobalHooker());
            m_KeyboardHookManager.Enabled = true;
            m_KeyboardHookManager.KeyDown += HookManager_KeyDown;
            m_KeyboardHookManager.KeyUp += HookManager_KeyUp;



            m_MouseHookManager = new MouseHookListener(new GlobalHooker());
            m_MouseHookManager.Enabled = true;
            m_MouseHookManager.MouseDown += HookManager_MouseDown;
            m_MouseHookManager.MouseUp += HookManager_MouseUp;

        }

        private void HookManager_KeyDown(object sender, KeyEventArgs e)
        {
            label1.Text = e.KeyData.ToString() + " Pressed";
        }

        private void HookManager_KeyUp(object sender, KeyEventArgs e)
        {
            label1.Text = e.KeyData.ToString() + " Released";
        }

        private void HookManager_MouseUp(object sender, MouseEventArgs e)
        {
            label1.Text = e.Button.ToString() + " Released";
        }


        private void HookManager_MouseDown(object sender, MouseEventArgs e)
        {
            label1.Text = e.Button.ToString() + " Pressed";
        }

    }
}
于 2013-05-28T00:45:02.873 回答