Skip to content

Repository files navigation

nugetmaster

Mouse and Keyboard Hooking Library in c#

What it does?

This library allows you to tap keyboard and mouse, to detect and record their activity even when an application is inactive and runs in background.

Prerequisites

  • Windows: .Net 4.0+

Installation and sources

 nuget install MouseKeyHook

Usage

privateIKeyboardMouseEventsm_GlobalHook;publicvoidSubscribe(){// Note: for the application hook, use the Hook.AppEvents() insteadm_GlobalHook=Hook.GlobalEvents();m_GlobalHook.MouseDownExt+=GlobalHookMouseDownExt;m_GlobalHook.KeyPress+=GlobalHookKeyPress;}privatevoidGlobalHookKeyPress(objectsender,KeyPressEventArgse){Console.WriteLine("KeyPress: \t{0}",e.KeyChar);}privatevoidGlobalHookMouseDownExt(objectsender,MouseEventExtArgse){Console.WriteLine("MouseDown: \t{0}; \t System Timestamp: \t{1}",e.Button,e.Timestamp);// uncommenting the following line will suppress the middle mouse button click// if (e.Buttons == MouseButtons.Middle) { e.Handled = true; }}publicvoidUnsubscribe(){m_GlobalHook.MouseDownExt-=GlobalHookMouseDownExt;m_GlobalHook.KeyPress-=GlobalHookKeyPress;//It is recommened to dispose itm_GlobalHook.Dispose();}

(also have a look at the Demo app included with the source)

How it works?

This library attaches to windows global hooks, tracks keyboard and mouse clicks and movement and raises common .NET events with KeyEventArgs and MouseEventArgs, so you can easily retrieve any information you need:

  • Mouse coordinates
  • Mouse buttons clicked
  • Mouse drag actions
  • Mouse wheel scrolls
  • Key presses and releases
  • Special key states

Additionally, there are MouseEventExtArgs and KeyEventExtArgs which provide further options:

  • Input suppression
  • Timestamp
  • IsMouseDown/Up
  • IsKeyDown/Up.

Troubleshooting and support

  • Usage or programming related question? Post it on StackOverflow using the tag mousekeyhook
  • Found a bug or missing a feature? Feed the issue tracker

Current project build status

The CI builds are generously hosted and run on the Travis and AppVeyor infrastructures.

Travis-CIAppVeyor
mastermastermaster
vNextvNextvNext

History

YearURL
2000 - 2008http://www.codeproject.com/KB/cs/globalhook.aspx
2008 - 2015https://globalmousekeyhook.codeplex.com/
2015 - nowhttps://github.com/gmamaladze/globalmousekeyhook

Quick contributing guide

  • Fork and clone locally
  • Create a topic specific branch. Add some nice feature.
  • Send a Pull Request to spread the fun!

License

The MIT license (Refer to the LICENSE.md file)

About

This library allows you to tap keyboard and mouse, detect and record their activity even when an application is inactive and runs in background.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages