[python-win32] Re: Help on using win32api.SendMessage to send
keystrokes
Tim Roberts
timr at probo.com
Thu Mar 31 22:16:03 CEST 2005
On Wed, 30 Mar 2005 20:46:43 -0500, Daniel F <nanotube at gmail.com> wrote:
>Well... i figured it out - turns out sending the keystrokes to the top
>window of notepad didnt work, but sending them to the Edit child
>window of notepad did the trick.
>
>But this brings me to another question, although of a less urgent
>manner. i had to send WM_CHAR messages, rather than WM_KEYDOWN/KEYUP
>in order to get it to work. I have nothing against WM_CHAR, as long as
>everything works, but i am just curious why i was not able to achieve
>the same effect with the WM_KEYDOWN/KEYUP pair? any takers?
>
It depends entirely on what the application expects. When the keyboard
driver sends keystrokes, the generic keyboard driver translates the key
codes to characters, if possible. It will send WM_KEYDOWN, then WM_CHAR
(if an ASCII translation exists), then WM_KEYUP. Applications can
choose which ones they want to handle.
In your case, you are bypassing the keyboard driver stack entirely. The
standard edit control, which is all Notepad is, apparently looks only at
WM_CHAR. There is no a priori method for figuring out which one is
required. If you need a general solution, you send all three. In this
case, since you want a specific solution, you can send just WM_CHAR.
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-win32
mailing list