Code Monkey home page Code Monkey logo

asynckeystate.net's Introduction

AsyncKeyState.Net

Nuget Nuget Open issues Closed issues MIT License

Net Framework 4.7 Net Framework 4.8

This library provides an easy to use interface to use the native GetAsyncKeyState, GetKeyState and GetKeyboardState API.

To provide better compatibility to other implementations using VirtualKeyCodes i decided to not implement the enum myself and instead use the Windows Forms implementation which is a complete enum representing the native VK_ constants.

You can freely convert between Windows Forms Keys and WPF Key enum values.

NuGet

Install-Package AsyncKeyState.Net

Features

  • Get the current KeyStates of any virtual key using the AsyncInput class
  • Get and update all KeyStates at once using the KeyboardState class
  • Automatically thread safe KeyboardState using a thread static cache
  • Convert between WPF Key and Windows Forms Keys enum
  • Documented and tested class library

Examples

Using the AsyncInput class:

// returns a flags enum representing the state of the control key
AsyncInput.GetKeyState(Keys.Control);

// returns true if the ctrl key is currently pressed
AsyncInput.IsPressed(Keys.Control);

// and much more

Using the KeyboardState class: (Which also includes mouse states ;))

var keyboard = new KeyboardState();

for (int i = KeyboardState.MinKeyValue; i < KeyboardState.MaxKeyValue; i++)
{
    Console.WriteLine(keyboard.IsPressed((Keys)i));
}

Console.ReadLine();

You can get a thread static instance of KeyboardState by using:

var keyboard = KeyboardState.GetThreadStatic();

The thread static instance is automatically thread safe by design.

Contribute

The project file was generated using Visual Studio 2019.

Clone or download the repository and update/install the required NuGet packages.

You can help by reporting issues, adding new features, fixing bugs and by providing a better documentation.

Donate

Do you like this project and want to help me to keep working on it?

Then maybe consider to donate any amount you like.

Donate via PayPal

BTC     14ES7f4GB3vD1C8Faz6ywqTcdDevxZoMyY

ETH     0xd9E2CB12d310E7BF5E72F591D7A2b8820adced04

License

asynckeystate.net's People

Contributors

michel-pi avatar

Watchers

James Cloos 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.