Giter Club home page Giter Club logo

windows-user-action-hook's Introduction

Windows User Action Hook

Note: This Project is no longer maintained.

A one stop library for global windows user actions such mouse, keyboard, clipboard, & print events

Build Status

Kindly report only issues/bugs here . For programming help or questions use StackOverflow with the tag EventHook or Windows-User-Action-Hook.

Supported Events

  • Keyboard events
  • Mouse events
  • clipboard events
  • application events
  • print events

Development enviroment

  • Visual Studio 2017

Usage

Install by nuget

Install-Package EventHook

Sample Code:

using (var eventHookFactory = new EventHookFactory())
{
    var keyboardWatcher = eventHookFactory.GetKeyboardWatcher();
    keyboardWatcher.Start();
    keyboardWatcher.OnKeyInput += (s, e) =>
    {
        Console.WriteLine(string.Format("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname));
    };

    var mouseWatcher = eventHookFactory.GetMouseWatcher();
    mouseWatcher.Start();
    mouseWatcher.OnMouseInput += (s, e) =>
    {
        Console.WriteLine(string.Format("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y));
    };

    var clipboardWatcher = eventHookFactory.GetClipboardWatcher();
    clipboardWatcher.Start();
    clipboardWatcher.OnClipboardModified += (s, e) =>
    {
        Console.WriteLine(string.Format("Clipboard updated with data '{0}' of format {1}", e.Data, e.DataFormat.ToString()));
    };


    var applicationWatcher = eventHookFactory.GetApplicationWatcher();
    applicationWatcher.Start();
    applicationWatcher.OnApplicationWindowChange += (s, e) =>
    {
        Console.WriteLine(string.Format("Application window of '{0}' with the title '{1}' was {2}", e.ApplicationData.AppName, e.ApplicationData.AppTitle, e.Event));
    };

    var printWatcher = eventHookFactory.GetPrintWatcher();
    printWatcher.Start();
    printWatcher.OnPrintEvent += (s, e) =>
    {
        Console.WriteLine(string.Format("Printer '{0}' currently printing {1} pages.", e.EventData.PrinterName, e.EventData.Pages));
    };

    //waiting here to keep this thread running           
    Console.Read();

    //stop watching
    keyboardWatcher.Stop();
    mouseWatcher.Stop();
    clipboardWatcher.Stop();
    applicationWatcher.Stop();
    printWatcher.Stop();
}

alt tag

windows-user-action-hook's People

Contributors

buildbot171 avatar jabe avatar justcoding121 avatar lostmsu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

windows-user-action-hook's Issues

Cannot hook MsgBox

image
This is the window I want to hooked.
image
This is the result analysed by Spy++
image
I use the code about AppHook in README.MD, but I cannot see output about the MsgBox I want to hook.
image
This is the code I wrote following the demo in README.
If you can give me some advice or hints, I will be appreciate it, Thx !!!

License/Attribution Question

Hi,

I came across this SO post and noticed the update pointing to this repository.

I haven't tried it yet but at first sight this looks like a very useful project and with your permission I'll use it in my own OSS project, Rubberduck - I'm not very familiar with licenses and their interactions, but my project is under GPL3; would it be ok to use your work there?

I'd like to also give proper credit/attribution, so if that's ok with you I'll add your project to our "About" window alongside Antlr4, LibGit2Sharp and the other OSS projects Rubberduck is using, and I'll add a link to this repository in the attributions section of my readme file.

Cheers!

Language switch disable

When I'm using KeyboardWatcher hook, app suddenly disable Shift+Alt keyboard layout switch.
I can only switch layout in my application, which uses KeyboardWatcher.
Any other windows no longer able to swtich layout by Shift+Alt.

Also I noticed what hook is not working when I'm using remote desktop (mstsc for example).

WM_HOTKEY hook

Beautiful work! I think this library would be more complete if it also handled hotkeys; the API could intake a Keys flag enum value for the key combination, and internally work out the applicable +^% modifier string... or perhaps intake the hotkey string as an overload.

It also needs a way to identify hotkeys, without forcing a type on the client code - object would work, but a generic type argument would be even better. Something like this:

var key = Keys.Ctrl + Keys.Shift + Keys.R;
// generic type parameter is inferred for Register<T>
HotkeyWatcher.Register(MyHotkeyEnum.SomeCoolCommand, key);
HotkeyWatcher.Start();

When a hotkey message is captured, an event is raised and the corresponding "key" that the hotkey was registered with is sent back to the client code, who can then decide what to do.

Note: I'll submit a PR soon-ish :-)

It is needed "MouseMessages Enum" for wheelClick.

It is needed "MouseMessages Enum" for wheelClick.

519 : WHEELCLICK_DOWN
520 : WHEELCLICK_UP

namespace EventHook.Hooks
{
public enum MouseMessages
{
WM_MOUSEMOVE = 512,
WM_LBUTTONDOWN = 513,
WM_LBUTTONUP = 514,
WM_RBUTTONDOWN = 516,
WM_RBUTTONUP = 517,
WM_WHEELBUTTONDOWN = 519,
WM_WHEELBUTTONUP = 520,

WM_MOUSEWHEEL = 522
}
}

mousemove

How i can the mouse move event from being captured?

VB.Net - WM_PASTE

Could you be so kind to give me a example of using your awesome library in VB.Net

Also could this library be used to globally catch the WM_PASTE hook.
So you can detect user paste not only by ctrl v but also by context menu

Thanks so much for this library and your work

Unit Testing frameworks report System.AppDomainUnloadedException

In all the situations I have try to use the MouseWatcher inside a unit test, the testing framework (NUnit, xUnit) reports a this exception:

System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.

First guess is that, calling MouseWatcher.Stop(), doesn't stop all the running threads that it should.

I have tried:

  1. To isolate the call in it's own thread, and get the dispatcher to invoke the stop inside, and them abort the thread.
  2. To give that thread STA Apartment State, and the IsBackground property.

Nothing has worked yet. At the moment you call MouseWatcher.Start() you get the cited exception at the end of the test.

Thanks you.

ContextSwitchDeadlock in hosted environment

My app is a COM add-in for the VBE - it's basically hosted in a host (the VBE) that's itself hosted in a host (the VBA host app)... and add another host layer to that when I'm running it in the VS debugger.

Long story short, everything seems to work when I'm running in the VS debugger. But when it isn't (i.e. I just launch Excel and load the last build), bringing up the VBA editor stalls the Office host app, and one of my contributors has reported seeing this error message:

ContextSwitchDeadlock occurred
Message: Managed Debugging Assistant 'ContextSwitchDeadlock' has detected a problem in 'C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE'.
Additional information: The CLR has been unable to transition from COM context 0xfc79c8 to COM context 0xfc7910 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

I suspect I might need to somehow pass the VBE MainWindow's hWnd to the EventHook API, but can't be sure.

I don't understand why it works when the VS debugger is attached, and deadlocks when it isn't (actually that Managed Debugging Assistant message seems to imply a debugger was attached), but I've disabled all other hooks and the issue persists as long as I have EventHook hooks attached; the issue resolves itself if I instead disabled the EventHook hooks and leave mine (I have a TimerHook regularly checking if the VBE is the active window, and a Hotkey hook listening for WM_HOTKEY messages sent) - so I know for a fact that the problem is with EventHook hooks.

Has there been a large rebase?

The master in my fork seems to be very diverged from the one in this repository, and same commits have different hashes...

Error during initializing new Event hook

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.'

Application event

I am trying the library with n console application and I can see all events except Application.
I tried firs 4.6.2 and then changed to 4.5 but did not work either.
No exception.
What other things I can check ?

My OS Win 140.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.