GetKeyState (coredll)
Last changed: benp@deltaonesw.com-216.237.8.234

.
Summary
The GetKeyState function retrieves the status of the specified virtual key. The status specifies whether the key is up, down, or toggled (on, off—alternating each time the key is pressed).

C# Signature:

[DllImport("coredll.dll", SetLastError=true)]

public static extern short GetKeyState(VK nVirtKey);

VB Signature:

Declare Function GetKeyState Lib "coredll.dll" (ByVal nVirtKey As [VK]) As Short

User-Defined Types:

VK

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

This function is very similar to the user32 function of the same name

Tips & Tricks:

Please add some!

Sample Code:

This sample VB.net code will check whether the NumLock is on or off.

   Const VK_NUMLOCK As Integer = CInt(System.Windows.Forms.Keys.NumLock)
   Dim keystate As Short = GetKeyState(VK_NUMLOCK)
   If (keystate = 0) Then
      MsgBox("NumLock is off")
   Else
      MsgBox("NumLock is on")
   End If

Documentation
GetKeyState on MSDN