Giter Club home page Giter Club logo

csinputs's Introduction

CSInputs

This library allows you to send and read mouse / keyboard inputs even when app window inactive.

WinForms / Console Application .NET Framework 3.5+

Installation

You can install this package from Nuget Package Manager.

Install-Package CSInputs

OR

dotnet add package CSInputs

Usage Examples

-Send Inputs

Keyboard Inputs:

SendInput.Keyboard.Send(KeyboardKeys.F1);
SendInput.Keyboard.Send(KeyboardKeys.F1,Enums.KeyFlags.Down);
SendInput.Keyboard.Send(KeyboardKeys.F1,Enums.KeyFlags.Up);
SendInput.Keyboard.SendChar('A');
SendInput.Keyboard.SendString("Hello World!");

Mouse Inputs:

SendInput.Mouse.Send(MouseKeys.MouseLeft);

SendInput.Mouse.Send(MouseKeys.MouseLeft,Enums.KeyFlags.Down);
SendInput.Mouse.Send(MouseKeys.MouseLeft,Enums.KeyFlags.Up);

SendInput.Mouse.Send(MouseKeys.MouseLeft, KeyFlags.Down,new Point(150, 123),MousePositioning.Absolute);
SendInput.Mouse.Send(MouseKeys.MouseLeft, KeyFlags.Down,new Point(-5, -30),MousePositioning.Relative);

SendInput.Mouse.MoveTo(new Point(150, 123), Enums.MousePositioning.Absolute);

-Listen Inputs

First you need to instantiate a input listener.

ReadInput.InputListener listener = new ReadInput.InputListener();

Then you can subscribe for keyboard or mouse events to listen inputs.

listener.KeyboardInputs += Listener_KeyboardInputs;
listener.MouseInputs += Listener_MouseInputs;

-Sample Console Application

using System;
// System.Windows.Forms is required to work on console applications.
using System.Windows.Forms; 
using CSInputs.Enums;
using CSInputs.ReadInput;
using CSInputs.Structs;

internal class Program
{
    static void Main(string[] args)
    {
        // Instantiate InputListener
        InputListener inputListener = new InputListener();
        
        // Subscribe to KeyboardInputs event handler to listen keyboard inputs.
        inputListener.KeyboardInputs += InputListener_KeyboardInputs;
        
        // Subscribe to MouseInputs event handler to listen mouse inputs.
        inputListener.MouseInputs += InputListener_MouseInputs;
        Application.Run(); // Required to work on console applications,
    }

    private static void InputListener_MouseInputs(MouseData data, ref ModifierKey modifierKey)
    {
        if (data.Key == MouseKeys.MouseRight && data.Flags == KeyFlags.Up)
            Console.WriteLine("Someone just released the \"Right Click\"!");
    }

    private static void InputListener_KeyboardInputs(KeyboardData data, ref ModifierKey modifierKey)
    {
        if (data.Key == KeyboardKeys.Space && data.Flags == KeyFlags.Up)
            Console.WriteLine("Someone just released the \"Space\" key!");
    }
}

csinputs's People

Contributors

trksyln avatar

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.