Sendkeys 不发送或发送多个字符串

发布于 2024-12-26 03:27:32 字数 682 浏览 2 评论 0原文

我在Windows.Forms中制作了一个带有许多按钮的键盘,它们的内容是字母表的不同字符,就像真正的键盘一样。

现在的问题是,当我在 Windows 7 中使用键盘时,一切正常。但是,当我在 Windows XP 的触摸屏上使用键盘时,键盘会多次写入我刚刚按下的按钮的内容,或者不会在文本框中写入任何内容。

下面是一些示例代码:

Button temp = sender as Button;
SendKeys.SendWait(temp.Text);

我尝试过 SendKeys.Flush 和

<appSettings>

<add key="SendKeys" value="SendInput"/>
</appSettings>

app.config 的内部,

这是这里的解决方案 msdn。但它并没有解决问题。

我做错了什么?

编辑:现在我发现第一个字母总是完美的。之后一切都变得很糟糕。除了 SendKeys.Flush 之外,我还可以尝试其他方法吗?

I made a keyboard in Windows.Forms with many Buttons and the content of them are the different characters of the Alphabet like a real keyboard.

Now the problem is when I am using the Keyboard in Windows 7 everything works perfectly. But when I use the Keyboard on the Touchscreen with Windows XP the keyboard writes multiple times the content of the button I just pressed or does not write anything inside of the textbox.

Here is some example code:

Button temp = sender as Button;
SendKeys.SendWait(temp.Text);

I have tried SendKeys.Flush and the

<appSettings>

<add key="SendKeys" value="SendInput"/>
</appSettings>

inside of the app.config

which is the solution here msdn. But it didnt fix the Problem.

What am I doing wrong?

Edit: Now I found out the first letter always works perfectly. After that everything turns awful. Is there something else than SendKeys.Flush that I could try?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

公布 2025-01-02 03:27:32

在第一个字母之后您将失去焦点...在调用 SendWait 之前将焦点重置到目标。

You're losing focus after the first letter... reset focus to the target before calling SendWait.

暖心男生 2025-01-02 03:27:32

sendkeys 函数确实不是最好的函数。
使用 winApi,更具体地说使用 PostMessage 会更好。

这是一个示例: PostMessage WM_KEYDOWN 发送多个键?

您将工作更多直接使用消息队列,但这也意味着您必须处理额外的事情,例如布局/本地化。

The sendkeys function really is not the best of functions.
Using the winApi and more specifically PostMessage will prove better.

Here is an example : PostMessage WM_KEYDOWN send multiply keys?

You will be working more directly with the message Queue, but it also means that you will have to handle extra things, such as layout/localization.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文