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

Tim Roberts timr at probo.com
Fri Apr 1 19:59:50 CEST 2005

On Thu, 31 Mar 2005 21:40:02 -0500, Daniel F <nanotube at gmail.com> wrote:

>Well, i do need a general solution, I was just using notepad as a test
>case... So it's definitely good for me to know about this - thanks!
>But i wonder, isnt there some kind of an "upstream" event, that could
>be generated and then would automatically generate and propagate all
>of the keydown, char, and keyup events, so i do not have to worry
>about sending all three?

You might investigate MapVirtualKey, keybd_event, and SendInput.  I have 
no clue whether these are exposed in the Python Win32 extensions.  
Overall, I would guess the three-message parlay is the lowest-impact method.

>also, as to roel's earlier post... could I please have some help on
>how to generate a bit field in python, in order to send a well-formed
>lParam to SendMessage, and thus create a well-formed WM_KEYUP/KEYDOWN

Python supports C expressions; you just build it by hand:

    bits = 0x8000000 | 0x00030000 | vkKey

Or, if you prefer the bit numbers explicitly:

    bits = (2 << 30) | (3 << 16) | vkKey

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

More information about the Python-win32 mailing list