简体   繁体   English

C#中的虚拟键盘

[英]Virtual keyboard in C#

I want to write an application that send various keycodes depending on which button the user clicked. 我想编写一个应用程序,根据用户点击的按钮发送各种密钥代码。 How would I send the keycodes? 我该如何发送密码? For example, how to emulate the 'a' press? 例如,如何模仿'a'按? How about modifier keys? 修饰键怎么样?

Once you have got the sending of key presses to another window sorted out, you are going to face another problem. 一旦你将按键发送到另一个窗口进行整理,你将面临另一个问题。 That is when the user clicks the button on your virtual keyboard the target window, the one you want to have receive the key press, will loose focus and the SendKeys will not seem to work. 也就是说,当用户单击虚拟键盘上的按钮时,目标窗口(您希望接收按键的窗口)将失去焦点,SendKeys似乎无法正常工作。

There many solutions to this problem, but the quick and dirty solution that requires minimal effort is to change the style of your virtual keyboard window to include WS_EX_NOACTIVATE 这个问题有很多解决方案,但需要最少努力的快速而肮脏的解决方案是将虚拟键盘窗口的样式更改为包含WS_EX_NOACTIVATE

See the answer I provided to the following question HERE for Windows Forms and if you want to do this using WPF I have a similar answer HERE 见我对以下问题提供了答案HERE Windows窗体,如果你想这样做,使用WPF我有一个类似的答案HERE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM