1. Herfried K. Wagner’s VB.Any
  2. .NET
  3. Frequently Asked Questions

Determining the state of a key on the keyboard

Determining the state of a key on the keyboard
<URL:https://dotnet.currifex.org/dotnet/faqs/getkeystate/en/>
----------------------------------------------------------------------------

Determining the state of a key on the keyboard

.NET 1.1 doesn't provide a managed way to determine if a key is pressed or
not except for modifier keys ('Control.ModifierKeys').  'GetAsyncKeyState'
can be used to determine if a key is pressed:

\\\
Imports System.Windows.Forms
.
.
.
Private Declare Auto Function GetAsyncKeyState Lib "user32.dll" ( _
    ByVal nVirtKey As Keys _
) As Boolean
///

Usage:

\\\
If GetAsyncKeyState(Keys.A) Then
    ...
End If
///