DllImport("User32.dll")]
private static extern short GetAsyncKeyState(
System.Windows.Forms.Keys vKey);
[DllImport("User32.dll")]
private static extern short GetAsyncKeyState(
System.Int32 vKey);
Note that this type of coding in .Net environment is called PInvoke
( platform invoke) feature as we are declaring and calling unmanaged libraries in .Net environment.
This Code works for all kind of Application domains running in Windows OS whether it is notepad, Messenger etc.
Calling APIs
(int)Keys
enumeration in calling function.
for example
// Check for keypresses
if (GetAsyncKeyState((int)Keys.Down) != 0)
or
// Check for keypresses
if (GetAsyncKeyState((int)Keys.Up) != 0)