Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
GetAsyncKeyState (user32)

// Somebody wiped this out for no good reason so here is a snippet of it

// Documentation for this API is available here

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

public static extern short GetAsyncKeyState(int vKey);

// An example

const int VK_PRINT = 0x2A;

const int VK_LWIN = 0x5B;

// Takes in a constant int that determines which key scan code to return

// The constants are available here

// You can also use Keys enums i.e. Keys.Left, but they may not match exactly.

// If the key is currently down, the value is non zero

if(GetAsyncKeyState(VK_LWIN) != 0)

// If the key has just been pressed, the first bit will be set to 1 so you can "AND" the rest of the bits away and check if the value equals

// A more detailed explanation is available here

if((GetAsyncKeyState(VK_PRINT) & 1) == 1)

// Another Example

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

public static extern bool GetAsyncKeyState(int vKey);

if(GetAsyncKeyState((int)Keys.A) == true)

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version