选项卡功能 - 在应用程序中发送密钥 [英] Tab Function - Sendkeys within the application

查看:115
本文介绍了选项卡功能 - 在应用程序中发送密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在屏幕键盘上模拟标签功能。



我将有2-5个文本框,我希望屏幕上的标签按钮按顺序标签到每个文本框。



我可以用select case写一个函数,但只是想知道是否有更简单的方法。



我看过sendkeys,但它似乎主要用于将密钥发送到其他应用程序。它可以用于我的需要,一个例子将不胜感激。

I need to simulate the tab function in a on screen keyboard.

I will have 2-5 textboxes, I want The onscreen tab button to tab to each textbox in order.

I can write a function using select case, but just wondering if there is a simpler way.

I have looked at sendkeys, but it seem it is mainly used to sendkeys to other applications. can it be used for my needs and an example will be appreciated.

推荐答案

使用 SendKeys 进行UI开发是一些虐待的迹象。至于屏幕键盘,如果你想让你的键盘系统全局化,它就没用了。许多应用程序(特别是WPF)甚至没有窗口控件用于输入控件,它们将忽略您的模拟键盘消息。使用它的唯一有效方法是通过P / Invoked Windows API SendInput

https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v = vs.85%29.aspx [ ^ ],

http://www.pinvoke.net/default.aspx/user32.sendinput [ ^ ]。



然后你真正模拟键盘,因为这个功能是低级的,就好像你生成真实的硬件事件,它也非常可靠且易于使用。



有一个相关的问题:你的键盘可能会从聚焦控件中窃取输入焦点,所以你除非y,否则将无法输入事件你采取特别措施来克服这个问题。对于 System.Windows.Forms ,我在这里描述了我的解决方案:应用程序焦点的获得和失败 [ ^ ]。



另见相关主题的过去答案:

如何在WPF中点击按键点击按键事件 [ ^ ],

创建虚拟键盘 [ ^ ],

编程在BACKSPACE按钮上 [ ^ ]。



这个是在WPF上的:如何在WPF按钮点击时触发按键按键事件 [ ^ ]。



祝你好运,

-SA
Using SendKeys for UI development is the sign of some abuse. As to the on-screen keyboard, it's simply useless, if you want to make your keyboard system-global. Many applications (notably, WPF) don't even windowed controls for input controls, they will ignore your emulated keyboard messages. The only valid way to use it would be via the P/Invoked Windows API SendInput:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^],
http://www.pinvoke.net/default.aspx/user32.sendinput[^].

Then you truly emulate a keyboard, as this function is low-level, acts as if you generated real hardware events, it is also very reliable and easy to use.

There is one related problem: your keyboard may steal input focus from a focused control, so you would not be able to input events, unless you take special measures to overcome this problem. For System.Windows.Forms, I described my solution here: Application focus getting and losing[^].

See also my past answers in related topics:
How to fire a Key Press event of a Key on button click in WPF[^],
Creating a Virtual Keyboard[^],
Programming on BACKSPACE button[^].

And this one is on WPF: How to fire a Key Press event of a Key on button click in WPF[^].

Good luck,
—SA


认为我破解了它。我已将所有文本框添加到数组中,并将活动文本框的名称作为参数发送到Findnext函数。



函数找到数组中的下一个项目并将焦点返回给它。
Think I have cracked it. I have added all of the textboxes in a array and send the name of the active text box as an argument to the Findnext function.

The function finds the next item in the array and returns focus to it.


这篇关于选项卡功能 - 在应用程序中发送密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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