11

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!

6
  • 7
    What is the motivation behind this holy quest? Commented Jul 22, 2012 at 5:09
  • Due to the extreme difficulty this has posed, it currently stands as a matter of interest and experimentation. My quest began however, as a way to customize the control keys of Windows MouseKeys, so that they could be used on a tablet (which I use) whilst retaining use of keys that are lost by the standard layout (ultimately, as legal mouse shortcuts for a popular MMORPG). Commented Jul 22, 2012 at 5:16
  • I wonder if you need to produce a hardware dongle of some sort that sits between the keyboard and the CPU, likely as part of the keyboard cable, and generate hardware-like key presses driven by some software driver. While I'm sure that something like this is possible, I also know that I don't have the wherewithal to create it, not now, and not in a million years. That's why to me it seems a holy grail quest. If you find the solution, please let me know. If on the other hand you find Castle Anthrax, let me know about that too!!! Commented Jul 22, 2012 at 5:47
  • That sounds especially difficult since my keyboard is compartmentalized in my tablet. Plugging in an exterior keyboard would solve half my problems. I'll keep you updated :) Commented Jul 22, 2012 at 6:04
  • >"What is the motivation behind this holy quest?" A Windows DirectX application that uses DirectInput; The only way to inject keystrokes is to modify the low level driver chain. A hardware device simulating HID input and addressable by an application would be a good solution. Commented Sep 3, 2014 at 13:50

4 Answers 4

5

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:

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm horrified and delighted. I'll give it a crack :) Thanks!
After much research / effort, I retain no idea on how to send keystrokes to a specific COM port. :|
2

I used this solution http://oblita.com/interception.html It fully meets my needs (sending keystrokes to direct input game)

Comments

0

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.

The 'Send' and 'SendWait' Methods seem to be the key ones.

Godspeed.

4 Comments

Hmm, it seems these methods also send the keystrokes to the active application. I wish MouseKeys was an application able to receive them :( Can somebody with experience with MSDN test this, to save me learning several new languages for something that mightn't yield anything?
Might almost be better off writing your own MouseKeys application... you can certainly move the mouse around with C#!(social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/…) and simulate mouse and keyboard events with the other library....
Tbh, methods of automating mouse usage is considered 'botting' in this MMORPG (and illegal), excluding use of Windows MouseKeys. Thus, the output must be a translation to MouseKeys. Very sensible suggestion however.
I posted another solution, completely different from the first. Hope these two posts inspired thought, at least!
0

I'm not on a Windows box to test it against MouseKeys, so no guarantees that it will work, but have you tried AutoHotkey?

1 Comment

AutoHotKey doesn't detect any keypress when using MouseKeys; the keystrokes are translating by MouseKeys into other inputs before AutoHotKey can get at 'em. Running AutoHotKey scripts to press keys supposed to trigger MouseKeys commands did not trigger them either. Thanks for the suggestion though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.