[python-win32] Help on using win32api.SendMessage to send keystrokes

Tim Roberts timr at probo.com
Tue Apr 5 18:41:34 CEST 2005

OnMon, 4 Apr 2005 17:28:09 -0400, Daniel F <nanotube at gmail.com> wrote:

>But now I am running into another problem. I was originally planning
>to use this on a game (final fantasy 7, in fact). I capture keystrokes
>in the system, then send them over the net and generate them on the
>remote comp, thus playing the game simultaneously and synchronously on
>two comps at once. Worked like a charm for any old windows app,
>including notepad that I used as my test app.
>But turns out ff7 uses directinput to get its keys (apparently...)
>because "normal" hooking of messages through SetWindowHookEx
>(actually, i'm using the pyHook package, which makes the process more
>pleasant, but is just a wrapper around the said function) doesnt work
>properly, nor does "normal" message injection through PostMessage.
>So, in a completely different tack, could anyone help me understand
>the relationship between directinput and the regular windows hook
>chain (so far it seems that directinput bypasses it completely),

Correct.  DirectInput (on NT systems, at least) disconnects the normal 
Windows keyboard/mouse event processing and routes a path from the human 
interface drivers (keyboard, mouse, joystick) directly into the 
application.  The application has exclusive use of the resources.

>how i would hook those keypresses/mouse moves, and how i would inject
>a keypress/mousemove for an application that is using directinput? Is
>that even possible?

No.  In order to do what you ask, you would need to write and install a 
set of kernel filter drivers to inject the events, and you really don't 
want to do that.  The API is not enough.

- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.

More information about the Python-win32 mailing list