C#中的屏幕KeyBoard [英] On-Screen KeyBoard in C#

查看:399
本文介绍了C#中的屏幕KeyBoard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的网络浏览器开发一个屏幕键盘。我希望在文本光标可见时显示键盘。 Web浏览器是主窗体,而键盘是辅助窗体。请帮助。



之前,我能够在主窗体中将数据从键盘发送到文本框,但我希望它对于网站的所有文本框都是通用的。浏览器本身。我希望它在文本光标可见时显示。

解决方案

首先,请看问题的评论。



要通用,而不是向任何控件发送任何消息,你可以在低级别生成输入事件,因为它是由键盘(和鼠标,顺便说一句)驱动程序完成的。然后输入将被分派到它们所属的位置。在键盘的情况下,键盘焦点所在的控件,这是每个整个桌面的一个控件。



这可以通过使用原始Windows API <$ c来实现$ c> SendInput :

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



它需要使用P / Invoke,但这已经为你完成了:http://www.pinvoke.net/default.aspx/user32.sendinput [ ^ ]。



您需要解决一些问题。首先,您不希望虚拟键盘的键(也是控件(按钮或其他任何东西))不能抓住焦点,而虚拟键盘也不需要激活。你真的不需要解决第二个问题:更好的设计可能只使用一个表单,然后控件可以是一个面板(可移动,可折叠,无论如何),而不是一个表单。钥匙可以简单地变得不可聚焦;毕竟,使用键盘按虚拟键盘键几乎没有意义。但是,如果您仍然需要解决上述任何问题,请查看我过去的答案:

应用程序焦点的获得和失败 [ ^ ],
以及以下情况:创建虚拟键盘 [ ^ ],

在BACKSPACE按钮上编程 [ ^ ],

应用程序焦点的获得和失败 [ ^ ]。



-SA

I am developing an on-screen keyboard for my web browser. I want to show the keyboard when the text cursor is visible. Web Browser is the main Form, while the Keyboard is the secondary Form. Please help.

Earlier, I am able to send data from keyboard to textbox in the main form, but I want it to be generic for all the textboxes of websites or browser itself. I want it to show whenever a text cursor is visible.

解决方案

First of all, please see a comment to the question.

"To be generic", instead of sending any messages to any controls at all, you can generate the input events on low level, as it is done by the keyboard (and mouse, by the way) drivers. Then the input will be dispatched where they belong. In case of keyboard, to the control where the keyboard focus is, which is one control per whole desktop.

This can be achieved by using raw Windows API SendInput:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

It will require using P/Invoke, but this is already done for you: http://www.pinvoke.net/default.aspx/user32.sendinput[^].

You will need to solve some problems though. First of all, you don't want the keys of the virtual keyboards, which are also controls (buttons or anything else), not to grab the focus, and the virtual keyboard to grab activation. You don't really need to solve the second problem: better design could be using only one form, and then the control could be a panel (removable, collapsible, whatever), not a form. And the keys can be simply made non-focusable; after all, it would be pretty much pointless to use a keyboard to press virtual keyboard keys. However, if you still have to solve any of the problems mentioned above, please see my past answers:
Application focus getting and losing[^],
and also, just in case: Creating a Virtual Keyboard[^],
Programming on BACKSPACE button[^],
Application focus getting and losing[^].

—SA


这篇关于C#中的屏幕KeyBoard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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