编程方式禁用大写锁定 [英] Programatically disable caps lock

查看:215
本文介绍了编程方式禁用大写锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用在工作的自动化程序的SendKeys。我一直在不厌其烦地,和我现在正在努力化解,我已经创造了所有的错误: - )

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 :-)

其中之一,就是当我使用的SendKeys 。发送(测试),如果是CapsLock键上,就会产生测试,而不是测试。

One of which, is that when I used SendKeys.Send("Test"), if the CapsLock is on, it will produce "tEST" as opposed to "Test".

我用下面的代码尝试检测CAPSLOCK状态,并在必要时将其切换:

I've used the following code to attempt to detect the capsLock state, and toggle it if necessary:

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(); <-Testing.
}



然后立即使用的SendKeys发送一些文字:

And then immediately use SendKeys to send some text:

SendKeys.SendWait("This Is An Over Capitalized Test String");



仍然出来为:这是一个在资本化测试字符串

Which STILL comes out as: "tHIS iS aN oVER cAPITALIZED tEST sTRING".

有没有什么办法来解决这个问题呢?感谢: - )

Is there any way to get around this problem? Thanks :-)

回答!只是为了澄清对别人,这个问题是通过使用解决

Answered! Just to clarify for anyone else, the problem was resolved by using

SendKeys.SendWait("{CAPSLOCK}" + text);



我第一次尝试使用:

I first attempted to use:

SendKeys.SendWait("{CAPSLOCK}");
SendKeys.SendWait("This Is An Over Capitalized Test String");



这并没有在所有的工作。

Which did not work at all.

推荐答案

这是否对你的工作?

    if(Control.IsKeyLocked(Keys.CapsLock))
        SendKeys.SendWait("{CAPSLOCK}This Is An Over Capitalized Test String");
    else
        SendKeys.SendWait("This Is An Over Capitalized Test String");

这篇关于编程方式禁用大写锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆