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.
Install-Package AsyncKeyState.Net
- Get the current
KeyStatesof any virtual key using theAsyncInputclass - Get and update all
KeyStatesat once using theKeyboardStateclass - 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 moreUsing 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 14ES7f4GB3vD1C8Faz6ywqTcdDevxZoMyY
ETH 0xd9E2CB12d310E7BF5E72F591D7A2b8820adced04
