This library provides an easy to use interface for the native GetAsyncKeyState
, GetKeyState
and GetKeyboardState
API and aswell synthesizes keyboard and mouse input.
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.
Install-Package AsyncKeyState.Net
This library is also available in the Github Package Registry.
- Get the current
KeyStates
of any virtual key using theAsyncInput
class - Get and update all
KeyStates
at once using theKeyboardState
class - Automatically thread safe KeyboardState using a thread static cache
- Convert between WPF Key and Windows Forms Keys enum
- Documented and tested class library
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.
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.
Do you like this project and want to help me to keep working on it?
Then maybe consider to donate any amount you like.
BTC bc1qp6zc73vy8pmr6lfe4cxa6eqzvkuer9hrjwpzza