Created
May 2, 2014 02:11
-
-
Save timheuer/57fb2ac130d7790a08a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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