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

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

问题描述

我在自动化程序中使用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.Send("Test")时,如果CapsLock处于打开状态,它将产生"tEST",而不是"Test".

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?

已回答!只是为了向其他人澄清,问题已通过使用

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

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

我第一次尝试使用:

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

根本不工作.

推荐答案

这对您有用吗?

    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天全站免登陆