在Windows窗体应用程序中的应用程序内未检测到Sendkeys事件

编程入门 行业动态 更新时间:2024-10-17 13:36:06
本文介绍了在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事件

本文发布于:2023-07-14 10:05:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   窗体   检测到   内未   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!