1

I did in my Form1 top :

using Gma.UserActivityMonitor;

Then declared :

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

Then in the Load event i did :

actHook.MouseClick += actHook_MouseClick;

Then in the bottom :

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

But once i run my application after a second before anything loaded i'm getting an exception on the file : HookManager.Callbacks.cs

On line:

throw new Win32Exception(errorCode);

The exception : The specified module could not be found

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: 

What or which module couldn't be found ?

I downloaded the source code of Version 2. And added all the files .cs from the : Gma.UserActivityMonitor directory on hard disk.

I'm not getting errors that something is missing so what can it be ?

Revuen Ben Dror
  • 237
  • 7
  • 17
  • Try looking at this CodePlex site http://globalmousekeyhook.codeplex.com/ the link you show is for a KeyboardHook only. – Mark Hall May 27 '13 at 23:53
  • Ok i tried the code in the link . I did what he said to do but when i'm running my application i'm geting an exception tried to follow someone question and answer how to fix it but didn't work so far. Please take al ook i'm updating my question. – Revuen Ben Dror May 28 '13 at 00:18
  • I found someone there asking same question as me with the same problem on the page of the project : Hello I am using c# express 2010 and getting this exception: Win32Exception was unhandled: The specified module could not be found. How can i solve it? I just have this: UserActivityHook actHook = new UserActivityHook(); actHook.OnMouseActivity += new MouseEventHandler(MouseMoved); – Revuen Ben Dror May 28 '13 at 00:27
  • And the answer he got : Replace the hMod parameter in SetWindowsHookEx to IntPtr.Zero. Seems to be an issue when using .NET 4.0, see http://stackoverflow.com/questions/2774741/module-not-found[^] but i searched i couldn't find anywhere SetWindowsHookEx and i didn't find hMod i did find it in one place but changing to IntPtr.Zero didn't work since IntPtr dosen't have any properties. – Revuen Ben Dror May 28 '13 at 00:29
  • Strongly consider *not* using global hooks if there is another way to solve your problem. I suspect that there is, but you don't tell us what you're trying to do so it's hard to give more specific advice. – Cody Gray - on strike May 28 '13 at 08:08

1 Answers1

4

I just downloaded the file from the GlobalMouseKeyHook CodePlex site and extracted it then I added the MouseKeyboardActivityMonitor.dll to my Project. Then I added the Using References to the Form. I am running Visual Studio 2010 Pro targeting the .Net 4 Client profile. I have had no problems

This is a Working example( This Code was modified from GlobalMouseKeyHook Demo project:

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";
        }

    }
}
Mark Hall
  • 53,938
  • 9
  • 94
  • 111
  • 1
    The .NET 4 specific issue is covered in [this question](http://stackoverflow.com/q/3671673/17034). You probably don't repro the OP's issue because you have a newer Windows version. – Hans Passant Jun 24 '13 at 09:50