问题
I'm looking for a language or library to allow me to simulate key strokes at the maximum level possible, without physically pressing the key.
(My specific measure of the level of the keystroke is whether or not it will produce the same output as a physical Key Press when my computer is already running key listeners (such as MouseKeys and StickyKeys)).
I've tried many methods of keystroke emulation;
The java AWT library, Java win32api, python win32com sendKeys, python ctypes Key press, and many more libraries for python and Java, but none of them simulate the key stroke at a close enough level to actual hardware.
(When Windows MouseKeys is active, sending a key stroke of a colon, semi colon or numpad ADD key just produces those characters, where as a physical press performs the MouseKeys click)
I believe such methods must involve sending the strokes straight to an application, rather than passing them just to the OS.
I'm coming to the idea that no library for these high (above OS code) level languages will produce anything adequate. I fear I might have to stoop to some kind of BIOS programming.
Does anybody have any useful information on the matter whatsoever?
How would I go about emulating key presses in lower level languages?
Should I be looking for a my-hardware-specific solution (some kind of Fujitsu hardware API)?
I almost feel it would be easier to program a robot to simply sit by the hardware and press the keys.
Thanks!
回答1:
Second solution, super convoluted, a ton of virtualization, diabolical, totally untested, but theoretically should work, unless the datasnip program doesn't actually write to the keyboard buffer, but instead simulates keystrokes like you've been trying to. That would suck, and I would find the description of their product to be highly misleading.
You'll need:
- http://www.priority1design.com.au/datasnip.html
- http://sourceforge.net/projects/com0com/
And some knowledge of writing to com ports... which, looks like there's a good python module here: http://pyserial.sourceforge.net/
First, write a small program that will send characters, hexcode, etc. as necessary to the COM port of your choosing. Second, create a virtual COM port pair using com0com. At this point, connect your program to one of the COM ports created, and datasnip to the other, making sure that both sides of the communication are using identical baud rates, parity and stop bits, and data length parameters.
At this point you should have a keyboard that is identical to a hardware one, as far as the OS can tell.
回答2:
I used this solution http://oblita.com/interception.html It fully meets my needs (sending keystrokes to direct input game)
回答3:
Can you use an MSDN language? They're fairly simple and well documented (google searches are better than the msdn website, for navigation, usually)
I found this bit, and I couldn't tell you if it simulates keystrokes at a level close enough to the hardware, but it does appear to be able to generate keystroke events that other programs can recognize, which is what your ultimate goal is.
- http://msdn.microsoft.com/en-us/library/ms171548.aspx
The 'Send' and 'SendWait' Methods seem to be the key ones.
- http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.sendwait.aspx
Godspeed.
回答4:
I'm not on a Windows box to test it against MouseKeys, so no guarantees that it will work, but have you tried AutoHotkey?
来源:https://stackoverflow.com/questions/11597892/simulate-key-press-at-hardware-level-windows