Sendkeys 不发送或发送多个字符串
我在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在第一个字母之后您将失去焦点...在调用 SendWait 之前将焦点重置到目标。
You're losing focus after the first letter... reset focus to the target before calling SendWait.
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.