GetAsyncKeyState (user32)
Last changed: -31.215.156.67

.

// 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)