title: Programmatically disable caps lock
body: <p>I'm using SendKeys in an automation program for work. I've been plodding along, and am now trying to iron out all the bugs that I've created :-)</p>
  
  <p>One of which, is that when I used SendKeys.Send("Test"), if the CapsLock is on, it will produce "tEST" as opposed to "Test".</p>
  
  <p>I've used the following code to attempt to detect the capsLock state, and toggle it if necessary:</p>
  
  <pre><code>bool tmp = Control.IsKeyLocked(Keys.CapsLock);
  if (tmp)
  {
       keybd_event(0x14, 0x45, KEYEVENTF_EXTENTEDKEY, (UIntPtr)0);
       keybd_event(0x14, 0x45, KEYEVENTF_EXTENTEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);
       //Application.DoEvents(); &lt;-Testing.
  }
  </code></pre>
  
  <p>And then immediately use SendKeys to send some text:</p>
  
  <pre><code>SendKeys.SendWait("This Is An Over Capitalized Test String");
  </code></pre>
  
  <p>Which STILL comes out as: "tHIS iS aN oVER cAPITALIZED tEST sTRING".</p>
  
  <p>Is there any way to get around this problem?</p>
  
  <p>Answered! Just to clarify for anyone else, the problem was resolved by using </p>
  
  <pre><code>SendKeys.SendWait("{CAPSLOCK}" + text);
  </code></pre>
  
  <p>I first attempted to use:</p>
  
  <pre><code>SendKeys.SendWait("{CAPSLOCK}");
  SendKeys.SendWait("This Is An Over Capitalized Test String");
  </code></pre>
  
  <p>Which did not work at all.</p>