Skip to content

Instantly share code, notes, and snippets.

@timheuer
Created May 2, 2014 02:11
Show Gist options
  • Save timheuer/57fb2ac130d7790a08a7 to your computer and use it in GitHub Desktop.
Save timheuer/57fb2ac130d7790a08a7 to your computer and use it in GitHub Desktop.
// http://msdn.microsoft.com/en-us/library/ms646301.aspx
[DllImport("user32.dll")]
internal static extern short GetKeyState(int keyCode);
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
internal static bool IsCapsLockOn()
{
return (KeyStateHelper.GetKeyState((int)VirtualKey.CapitalLock)) != 0;
}
internal static void TurnCapsLockOn()
{
// 0x14 is VK_CAPITAL
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
keybd_event((byte)VirtualKey.CapitalLock, 0x14, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event((byte)VirtualKey.CapitalLock, 0x14, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment