Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
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 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getasynckeystate

[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 https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes

// 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 https://www.unknowncheats.me/forum/c-c-c/62440-some-food-brain-all-getasynckeystate.html

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 PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions