在Windows窗体应用程序中的应用程序内未检测到Sendkeys事件 [英] Sendkeys event is not detected inside the application in windows form application

查看:108
本文介绍了在Windows窗体应用程序中的应用程序内未检测到Sendkeys事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Windows应用开发的新手。我正在开发一个Windows窗体应用程序,其布局如下:



有一个文本框,我使用SendKeys事件在应用程序内部创建了键盘。



问题是系统上的所有其他应用程序都能够检测到密钥,但应用程序内的文本框无法检测到密钥。



我尝试过:



受保护的覆盖CreateParams CreateParams 
{
get
{
CreateParams param = base.CreateParams;
param.ExStyle | = 0x08000000;
返回参数;
}
}

private void button14_Click(object sender,EventArgs e)
{//键盘中的一个键
if(checkBox1.Checked )
{
SendKeys.Send(Q);
}
其他
{
SendKeys.Send(q);
}
}

private void textBox1_TextChanged(object sender,EventArgs e)
{

}

解决方案

在调用SendKeys.Send()之前将焦点设置为textBox1,以确保焦点是接收输入。



 textBox1.Focus(); 
SendKeys.Send( Q);


Hi, I am new to windows app development. I am developing a Windows Form Application where the layout is as follows:

There is one textbox and i have created the keyboard inside the application using SendKeys event.

Problem is that all other application on the system are able to detect the keys but the textbox inside the application is not able to detect the keys.

What I have tried:

protected override CreateParams CreateParams
        {
            get
            {
                CreateParams param = base.CreateParams;
                param.ExStyle |= 0x08000000;
                return param;
            }
        }

private void button14_Click(object sender, EventArgs e)
        {//one of the Key in Keyboard
            if (checkBox1.Checked)
            {
                SendKeys.Send("Q");
            }
            else
            {
                SendKeys.Send("q");
            }
        }

private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

解决方案

Set the focus to textBox1 right before calling SendKeys.Send() to be sure that's what has focus to receive the input.

textBox1.Focus();
SendKeys.Send("Q");


这篇关于在Windows窗体应用程序中的应用程序内未检测到Sendkeys事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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