Giter Club home page Giter Club logo

winputmanager's Introduction

WinputManager

A simple library to access windows input API (such as system global hooks for input recording and simulate input events) easily using .Net (C#\VB .net).

An example of a simple code that captures keyboard input globally:

private void OnFormLoad() {
    // Setup keyboard hook
    keyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent;
    keyboardHook.Install();
}

// This method will be called whenever the user types any key
private bool KeyboardHook_OnKeyboardEvent(uint key, BaseHook.KeyState keyState)
{
    // Here goes you code that analyzes what to do with the captured input
    return false;
}

What's this?

WinputManager allows you to capture Windows common input (mouse and keyboard) easily. It works at system global level which means all of the low level input is being captured (By using the SetWindowsHookEx winapi).

It is the new library of InputManager (originally written for the commercial use of Mouse Recorder Pro).

The current version only allows setting up hooks and listening to common user input (such as mouse & keyboard). Input simulation is not yet supported.

What's new in this version?

WinputManager allows you to perform the following:

  • Recording mouse & keyboard input easily.
  • Consume mouse and input events you wish not to be processed by the system.
  • Code base was rebuilt - which means less bugs and a more reusable code flow.
  • Exceptions are thrown when hooking fails

Compiling and running this library

The library comes by default with a running working code example. You can run it just as any .Net project. Running it will open up an example window showing how to work with this library.

In order to use this library in your project please change the WinputManager project Output type to Class library (right clicking on Solution Explorer > WinputManager > Properties > Output type > Class library, and then rebuild it).

Recording user input

Using WinputManager you can easily capture mouse and keyboard inputs such as: mouse clicks, keyboard typing, mouse movements, mouse scrolling.

In order to the user input, you need to setup hooks using:

  • KeyboardHook - a class reponsible of capturing keyboard events.
  • MouseHook - a class reopnsible of capturing mouse events.

Your application will be notified by listening to any event the hook will raise.

KeyboardHook will only raise OnKeyboardEvent(uint key, KeyState keyState). MouseHook have 3 different events:

  • OnMouseMove(int x, int y)
  • OnMouseEvent(int mouseEvent)
  • OnMouseWheelEvent(int wheelValue)

All of the events should return false if the event shouldn't be consumed or true if the event will be consumed. Returning true simply means that the system will stop delivering the input to target window\application.

Here is a simple example on how to use this library:

KeyboardHook keyboardHook = new KeyboardHook();
MouseHook mouseHook = new MouseHook();

void InstallHooks() {
    // Setup keyboard hook
    keyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent;
    keyboardHook.Install();
    
    // Setup mouse hook
    mouseHook.OnMouseEvent += MouseHook_OnMouseEvent;
    mouseHook.OnMouseMove += MouseHook_OnMouseMove;
    mouseHook.OnMouseWheelEvent += MouseHook_OnMouseWheelEvent;
    mouseHook.Install();
}

void UninstallHooks() {
    keyboardHook.Uninstall();
    mouseHook.Uninstall();
}

private bool KeyboardHook_OnKeyboardEvent(uint key, BaseHook.KeyState keyState)
{
    Debug.WriteLine(String.Format("{0} key was {1}", 
        ((Keys) key).ToString(), 
        keyState == BaseHook.KeyState.Keydown ? "pressed" : "released"));

    return false;
}

private bool MouseHook_OnMouseWheelEvent(int wheelValue)
{
    Debug.WriteLine(String.Format("{0} mouse wheel value captured",
        (MouseHook.MouseWheelEvents) wheelValue).ToString());

    return false;
}

private bool MouseHook_OnMouseMove(int x, int y)
{
    Debug.WriteLine(String.Format("Mouse moved to: {0},{1}", x, y));
    return false;
}

private bool MouseHook_OnMouseEvent(int mouseEvent)
{
    Debug.WriteLine(String.Format("{0} mouse event occured", (MouseHook.MouseEvents) mouseEvent));
    return false;
}

winputmanager's People

Contributors

shy2net 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

Watchers

 avatar  avatar

winputmanager's Issues

Is there any way to distinguish between upper and lower case?

Hi shy2net, first of all thanks for posting your code, if I can adapt it to my application it will save me a lot of headaches.

It's being very useful for me but I can't find a way to distinguish the characters entered in lowercase, the ascii codes I get are always uppercase. I have also tried using the "ScanCode" but since the position of the keys varies based on the region of the keyboard it does not work for me either.

Thanks in advance and excuse my English, it is not my native language.

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.