区分键盘的真实和虚拟按键 [英] distinguish between keyboard's Real and Virtual key presses

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

问题描述

我正在用C#编写一个程序,该程序必须模拟键盘的按键命令.

I'm writing a program in C#, that have to simulate keyboard's key press commands.

问题是-我需要模拟逼真的"键盘按钮的点击,而不是假的.例如,据我了解:

The problem is - I need to simulate "realistic" keyboard button clicks, not the fake ones. For example, as far as I understand:

  • 当用户按下键盘上的任何按钮时-信号通过USB发送,然后通过键盘驱动程序进行处理.

  • when user presses any button on the keyboard - the signal is sent via USB, and then proceed via keyboard's driver.

使用API​​时(SendInput,SendKeys,KeyBoardEvent或其他),我们会绕过USB和驱动程序,因此基本上可以通过全局挂接方法来跟踪此类按压.

when API's are used (SendInput, SendKeys, KeyBoardEvent, or whatever) - we bypass USB and driver, so basically these kind of presses can be tracked via global hook method..

您如何模拟逼真的按键?

  • 我对C ++不了解,因此不能选择编写自定义驱动程序.

  • I don't have knowledge in C++ so writing a custom driver is not an option.

我不介意使用微控制器或任何其他硬件解决方案",只要价格便宜即可.

I don't mind using microcontrollers or any additional hardware "solutions", as long as it's cheap..

也许可以通过USB电缆连接两台PC,以便从PC2到PC1发送逼真的键盘按键信号?

maybe it's possible to connect two PC's via USB cable for the purpose of sending realistic keyboard button press signals from PC2 to PC1?

那是什么方法?

推荐答案

您可以使用全局键盘钩子(WH_KEYBOARD_LL)标识由SendInput()发送的键盘事件. 它是回调方法 LowLevelKeyboardProc 接收到的 KBDLLHOOKSTRUCT 作为参数.

You can identify keyboard event sent with SendInput() with global keyboard hook(WH_KEYBOARD_LL). It's callback method LowLevelKeyboardProc recieves KBDLLHOOKSTRUCT as a parameter.

如果在KBDLLHOOKSTRUCT中设置了LLKHF_INJECTED标志.则通过SendInput()注入了flags键盘事件.

If LLKHF_INJECTED flag is set in KBDLLHOOKSTRUCT.flags keyboard event was injected with SendInput().

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

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