如何区分真实按键和虚拟按键? [英] How to tell real and virtual keypresses apart?

查看:181
本文介绍了如何区分真实按键和虚拟按键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将"Z"键替换为"Y",反之亦然.
因此,如果用户在键盘上按下"Z",则我会抓住并
禁止它并发送"Y".

麻烦的是,到目前为止,我还没有找到区分真实钥匙的方法
事件和假事件.这意味着身体受到压迫
检测到"Z",将其抑制,将发送"Y",但输入
该系统就像真正的按键一样,因此被抓住,并且
被抑制,被无限循环中的"Z"代替.

"Z"和"Y"只是示例,我的应用程序应该能够
捕捉任何关键组合并替换为任何其他组合.

键盘挂钩是通过SetWindowsHookEx()在
上安装的 密钥发送是通过SendInput()完成的.

评论:
通过SendInput()发送密钥时,您想发生什么?"
我希望假的按键可以在没有
的情况下到达重点应用程序 被键盘挂钩拦截和压制. (我只想要
使用真正的按键就可以做到这一点.)

您可以使用标志和测试来防止事件中的无限循环
处理程序."

I''m trying to replace the "Z" key with "Y" and vice versa.
So if the user hits "Z" on the keyboard then I catch and
suppress it and send a "Y" instead.

Trouble is that so far I found no way to tell apart real key
events and fake ones. This means that a physically pressed
"Z" is detected, suppressed, a "Y" is sent but that enters
the system just like a real key press so gets caught and
suppressed, replaced by a "Z" and so on in an infinite loop.

"Z" and "Y" are just examples, my application should be able
to catch any key combo and replace with any other combo.

The keyboard hook is installed via SetWindowsHookEx() while
the key sending is done with SendInput().

COMMENTS:
"What do you want to happen when you send the key via SendInput()?"
I want the fake keypress to arrive to the focused application without
being intercepted and suppressed by the keyboard hook. (I only want
to do that with real keypresses.)

"You can use flags and tests to prevent the infinite loop in the event
handler."
What sort of flags and tests?

推荐答案

通过SendInput()发送密钥会发生什么?

您可以使用标志和测试来防止事件处理程序中的无限循环.
What do you want to happen when you send the key via SendInput()?

You can use flags and tests to prevent the infinite loop in the event handler.


Z和Y的变化看起来像英语和德语的键盘设置.因此,InputLanguage.CurrentInputLanguage可以为您提供帮助吗(即您以后无需再进行更改)?
That change of Z and Y looks like English versus German keyboard settings. Thus, could InputLanguage.CurrentInputLanguage help in your case (i.e. you would no more need to change later on)?


这篇关于如何区分真实按键和虚拟按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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