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!

Anti Earth
  • 4,671
  • 13
  • 52
  • 83
  • 6
    What is the motivation behind this holy quest? – Hovercraft Full Of Eels Jul 22 '12 at 05: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). – Anti Earth Jul 22 '12 at 05: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!!! – Hovercraft Full Of Eels Jul 22 '12 at 05: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 :) – Anti Earth Jul 22 '12 at 06: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. – Mike Sep 03 '14 at 13:50
  • Have you tried [RegisterHotKey](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx)? – SMUsamaShah Feb 18 '16 at 07:22

4 Answers4

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.

rfinz
  • 372
  • 6
  • 14
2

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

Maxim Ky
  • 341
  • 2
  • 6
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.

rfinz
  • 372
  • 6
  • 14
  • 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? – Anti Earth Jul 22 '12 at 06:31
  • Might almost be better off writing your own MouseKeys application... you can certainly move the mouse around with C#!(http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/e2a4df07-ea48-4c4c-8281-6db1b4247e4b/) and simulate mouse and keyboard events with the other library.... – rfinz Jul 22 '12 at 07:11
  • 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. – Anti Earth Jul 22 '12 at 07:31
  • I posted another solution, completely different from the first. Hope these two posts inspired thought, at least! – rfinz Jul 22 '12 at 08:10
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?

Sam King
  • 2,068
  • 18
  • 29
  • 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. – Anti Earth Jul 22 '12 at 06:25