/// <summary>
/// This method tests whether a key is down or not.
/// </summary>
/// <param name="k">The key to test.</param>
/// <returns>True if the keys is down.</returns>
public static bool IsKeyDown(System.Windows.Forms.Keys k)
{
short state = GetKeyState((int)k);
if((state & 0x8000) == 0x8000) //It's down
return true;
return false;
}
/// <summary>
/// This method tests whether a key is on or not.
/// </summary>
/// <param name="k">The key to test.</param>
/// <returns>True if the keys is on.</returns>
public static bool IsKeyOn(System.Windows.Forms.Keys k)
{
short state = GetKeyState((int)k);
if((state & 0x0001) == 0x0001) //It's on
return true;
return false;
}
Alternative Managed API:
Do you know one? Please contribute it!
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).
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).
NEW: SmartAssembly 5.0
Automated Error Reporting: get a volume of crash reports and a complete state of your program whenever it fails, and improve the quality of your program.