[comp.windows.ms.programmer] Duplicating keyboard messages...?

lwallace@javelin.es.com (Raptor) (03/20/91)

Hi all, I'm trying to write sort of a macro recorder.  It'll send imaginary
keystrokes to other applications in an effort to invoke some of their menu
accelerator functions.

I've sent WM_KEYUPs and WM_KEYDOWNs to other applications, and used Spy to
examine them.  The messages I send are almost identical to the messages Spy
shows when I click on the app and press the keys myself.  However, the only
application I've been able to get to respond to my program is SDKHelp.  I've
only tried the apps in the SDK tools group; Dialog and SDKPaint ignore me.

The only difference I can detect between my app's messages and the messages
from the keyboard are those "used internally by Windows" bits in the WM_KEY*
message lParams.  And so far I've only sent WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN
and WM_SYSKEYUP messages.  Spy tells me WM_MENUCOMMAND shows up when I press
keys; please tell me this is something done in response to the WM_KEY* messages.

What else does my program have to do?  Am I seeing an idiosyncracy in Microsoft
tools, and can I expect "normal" Windows applications to react as I expect?

Thanks in advance!

-- 
Lynn Wallace			   |I am not an official representative of
Evans and Sutherland Computer Corp.| <- E&S.  Or for that matter, unofficial.
Salt Lake City, UT 84108	   |Internet: lwallace@javelin.sim.es.com
			War not make one great! -- Yoda

risto@tuura.UUCP (Risto Lankinen) (03/25/91)

lwallace@javelin.es.com (Raptor) writes:

>Hi all, I'm trying to write sort of a macro recorder.  It'll send imaginary
>keystrokes to other applications in an effort to invoke some of their menu
>accelerator functions.

>I've sent WM_KEYUPs and WM_KEYDOWNs to other applications, and used Spy to
>examine them.

Hi!

Since you cannot be sure whether the target reacts upon WM_KEYUP/DOWN or
the resulting WM_CHAR/SYSCHAR/MENUCHAR message, you should not send these
messages with SendMessage(), because they bypass the target application's
TranslateMessage() call in its message loop.  You should use PostMessage()
instead, which allows the target app. to translate the WM_KEYUP/DOWN's as
appropriate.

Terveisin: Risto Lankinen
-- 
Risto Lankinen / product specialist ***************************************
Nokia Data Systems, Technology Dept *  2                              2   *
THIS SPACE INTENTIONALLY LEFT BLANK * 2 -1 is PRIME!  Now working on 2 +1 *
replies: risto@yj.data.nokia.fi     ***************************************

lwallace@javelin.es.com (Raptor) (03/29/91)

risto@tuura.UUCP (Risto Lankinen) writes:
>lwallace@javelin.es.com (Raptor) writes:
>>I've sent WM_KEYUPs and WM_KEYDOWNs to other applications, and used Spy to
>>examine them.

>Since you cannot be sure whether the target reacts upon WM_KEYUP/DOWN or
>the resulting WM_CHAR/SYSCHAR/MENUCHAR message, you should not send these
>messages with SendMessage(), because they bypass the target application's
>TranslateMessage() call in its message loop.  You should use PostMessage()
>instead, which allows the target app. to translate the WM_KEYUP/DOWN's as
>appropriate.

Hey, thanks for answering!  I'm getting desperate about this problem;
it's one of two that are keeping me from getting my application done.

Alas, I misinformed you.  I do indeed use PostMessage(), with the same
lack of results.

Lately, I've tried both SetFocus() (before sending the messages) and
WaitMessage() (between the KEYDOWN and KEYUP messages) to see if I was
hogging any resources and preventing the other application from
processing my messages.  No improvement.

Why in the heck does SDKHelp work and all these others don't??????  A
possible hint is, the keystroke I'm sending SDKHelp is F1, while all
the other attempts have been control-characters (requiring two
messages...).  I've used Spy again and tried to get my messages to
appear *exactly* as the actual keystrokes, but there's only so much
I've been able to accomplish to that end.

Again, thanks for the input.
-- 
Lynn Wallace			   |I am not an official representative of
Evans and Sutherland Computer Corp.| <- E&S.  Or for that matter, unofficial.
Salt Lake City, UT 84108	   |Internet: lwallace@javelin.sim.es.com
			War not make one great! -- Yoda