创建一个屏幕键盘 [英] Create an On-screen Keyboard

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

问题描述

我用PostMessage的模拟键盘的程序,它是在后台。它做工精细,除了需要转向物理键盘上的字符。如何模拟转变?

I use PostMessage to simulate keystrokes in a program that is in the background. It work fine except for characters that need shift on the physical keyboard. How do I simulate shift? "

在code我用大致是:

The code I use is roughly:

 VK vk = VkKeyScanEx (c, GetKeyboardLayout (0));

 AttachThreadInput (_attachedThredId, _attachedProcessId, true);
 PostMessage       (_window, WM_KEYDOWN, vk.key, 0x1);
 PostMessage       (_window, WM_KEYUP,   vk.key, 0xC0010001);
 AttachThreadInput (_attachedThredId, _attachedProcessId, false);

我应该如何处理VK的扩展部分?

How should I handle Extended part of VK?

修改

我试图创建一个屏幕上的键盘。在屏幕键盘上的每个按键模拟按键的顺序。接收机是一个古老的程序执行根据所执行的键盘序列不同的任务。
键盘序列如下:

I'm trying to create an on-screen keyboard. Each button on the on-screen keyboard simulates a sequence of keystrokes. The receiver is an old program that performs different tasks depending on the keyboard sequence that is performed. Keyboard sequences is as follows


  • {} ESC {NN} ESC NN

  • {} ESC NN

  • ½NN

  • §NN

其中{} ESC模拟pressing Esc键,NN是十六进制值和§/半让节目听。

where {ESC} simulate pressing the Esc key, NN are hex values and §/½ get the program to listen.

通常我们有特殊的物理键盘来控制程序,但它们很昂贵。所以在测试环境中,我们并不总是有物理键盘,我们要进入这些codeS手动

Normally we have special physical keyboard to control the program, but they are expensive. So in a test environment where we do not always have the physical keyboards, we have to enter these codes manually

推荐答案

您必须妥协:

如果你想为模拟键盘输入,然后你必须使用 SendInput ,这意味着在该窗口的当前焦点的怜悯。 SendInput 就像是打你的物理键盘上的键。您可以使用键盘发送键击到特定窗口的唯一方法就是 ALT + TAB 到右侧窗口中。

If you want to simulate keyboard input, then you must use SendInput, which means being at the mercy of which window currently has focus. SendInput is like hitting the keys on your physical keyboard. The only way you can send your keystrokes to a specific window using your keyboard is to ALT+TAB to the right window.

如果您要发送键击到特定窗口,然后你承担时髦的行为:

If you want to send keystrokes to a specific window, then you incur funky behavior:


  1. 应用程序处理输入不同。和简单的 WM_KEYDOWN / WM_KEYUP 消息不检测键盘输入的唯一途径。例如也有键盘状态( GetKeyboardState()),你将有一个更难时间来模拟。这是最有可能您遇到了什么。

  2. 应用程序可能会依赖于受关注,而接收键盘输入消息的标准行为。通过发布消息,这些应用程序,调用怪掉的无序行为可能会崩溃它们。

  3. 现在,在系统上的多个窗口可以同时被接收键盘输入。这也可能会导致奇怪的行为。

  4. (等等)挂钩将不会调用此输入,键盘/输入驱动器不会看到它,它不会被之类的东西DirectInput的认可...基本上这是一个永无止境的拼凑通过做一些坏熊路的问题。

  1. Applications handle input differently. And simple WM_KEYDOWN / WM_KEYUP messages are not the only way to detect keyboard input. For example there is also the keyboard state (GetKeyboardState()) which you will have a harder time simulating. This is most likely what you're experiencing.
  2. Applications may RELY on the standard behavior of having focus while receiving keyboard input messages. By posting messages to these applications, you invoke strange out-of-order behavior that may crash them.
  3. Now multiple windows on the system can be receiving keyboard input at the same time. This might also cause strange behavior.
  4. (etc...) Hooks won't be called for this input, your keyboard / input drivers won't see it, it won't be recognized by things like DirectInput... basically it's a never-ending patchwork of issues by doing something the bad-bear way.

有就是围绕这些副作用没办法;它做的东西黑幕的后果。

There is no way around those side-effects; it's the consequence of doing shady stuff.

:一种为您的目的,因为你的目标一个特定的应用程序,可以结合使用 PostMessage的 SetKeyboardState 模拟包括移仓键盘状态。

A solution for your purposes, because you're targeting a single specific application, may be to use PostMessage in conjunction with SetKeyboardState to simulate the keyboard state including shift positions.

这篇关于创建一个屏幕键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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