SENDKEYS RECAP

From: Bob Nash <BNash_at_smud.org>
Date: Mon, 31 Jan 2005 08:23:52 -0800

For what it is worth, here is a recap of a SENDKEYS thread from 2002.:

****************
MESSAGE 7
****************
From: Morten A. Steien [bamsen_at_dod.no]
Sent: Thursday, July 04, 2002 8:03 AM
To: sftalk_at_forth.com
Subject: [sftalk] Re: Replicating functionality of VisualBasic's
SendKeys command

After a bit of testing I arrived at a combination that works, even
though I don't know exactly why. :-)

DUP WM_KEYDOWN [CHAR] E $20000000 SendMessage DROP
DUP WM_KEYDOWN [CHAR] P $00000001 PostMessage DROP

The first lParam value states that Alt is pressed with the key.
If I don't change the first to SendMessage it won't work.

Now I can paste to CodeWright without giving it focus, so
that I can continue generating data in SF and paste again.

Using VK_F10 only resulted in 'y' being typed in my document.
Using VK_CONTROL did nothing visible. Together with [CHAR] V it
just typed 'v' in my document.

Best Regards,
Morten A. Steien
Norsk Hydro IS-Partner

****************
MESSAGE 6
****************
From: Morten A. Steien [bamsen_at_dod.no]
Sent: Wednesday, July 03, 2002 6:05 AM
To: sftalk_at_forth.com
Subject: [sftalk] Re: Replicating functionality of VisualBasic's
SendKeys command

I'm struggeling with a similar problem.
I want to send Ctrl+V to CodeWright to paste in text that I have
put on the clipboard.

My code is as follows:

256 Buffer: WinText
: Activate_CodeWright ( -- )
  hWnd GW_HWNDFIRST GetWindow
  Begin
    Dup WinText 255 GetWindowText If
      WinText 10 s" CodeWright" Compare 0=3D If
        Dup SetForegroundWindow Drop
        Dup WM_KEYDOWN 17 1900545 PostMessage Drop
        Dup WM_KEYDOWN 86 3014657 PostMessage Drop
        Dup WM_KEYUP 86 -1070727167 PostMessage Drop
        Dup WM_KEYUP 17 -1071841279 PostMessage Drop
        Then
      Then
    GW_HWNDNEXT GetWindow
    Dup 0=3D Until
  Drop
  ;

The result of this word is that CodeWright is activated and
a 'v' is printed at the current cursor position.

The problem is that pressing Ctrl (17) is ignored.
I don't know how to determine what to put in lParam and have tried
to copy what keydown and keyup messages are sent to my own window.

Any suggestions are greatly appreciated.

Best Regards,
Morten A. Steien
Norsk Hydro IS-Partner

****************
MESSAGE 5
****************
From: Mike Ghan [mikeghan_at_logix-controls.com]
Sent: Wednesday, July 03, 2002 7:20 AM
To: sftalk_at_forth.com
Subject: [sftalk] Re: Replicating functionality of VisualBasic's
SendKeys command

Morten,

Try the following (untested):

DUP WM_KEYDOWN VK_CONTROL $00000001 PostMessage DROP
DUP WM_KEYDOWN [CHAR] V $00000001 PostMessage DROP
DUP WM_KEYUP [CHAR] V $C0000001 PostMessage DROP
DUP WM_KEYUP VK_CONTROL $C0000001 PostMessage DROP

Refer to a Windows API for details on LPARAM "magic" number bit values
for WM_KEYDOWN and virtual key codes such as VK_CONTROL (value=3D17).
Also, it is possible CodeWright tests for which control key (left or
right) for different handling, in which case CodeWright would call the
GetKeyState function to determine the state of a control key. This is
tougher problem - you'll need to intercept and modify the Windows
messages sent to CodeWright via the SetWindowsHookEx function. I've
not attempted this before. Another possibility is to simulate menu
access by sending the following keys F10 (access menu, virtual key
code =3D VK_F10), E (edit menu), P (paste) or whatever menu sequence
CodeWright uses. Note we don't need shifted (e.g. control or alt)
keys.

Keep us posted.

Good Luck,
Mike

****************
MESSAGE 4
****************
-----Original Message-----
From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com]On
Behalf
Of Morten A. Steien
Sent: Wednesday, July 03, 2002 6:05 AM
To: sftalk_at_forth.com
Subject: [sftalk] Re: Replicating functionality of VisualBasic's
SendKeys command

I'm struggeling with a similar problem.
I want to send Ctrl+V to CodeWright to paste in text that I have
put on the clipboard.

My code is as follows:

256 Buffer: WinText
: Activate_CodeWright ( -- )
  hWnd GW_HWNDFIRST GetWindow
  Begin
    Dup WinText 255 GetWindowText If
      WinText 10 s" CodeWright" Compare 0=3D If
        Dup SetForegroundWindow Drop
        Dup WM_KEYDOWN 17 1900545 PostMessage Drop
        Dup WM_KEYDOWN 86 3014657 PostMessage Drop
        Dup WM_KEYUP 86 -1070727167 PostMessage Drop
        Dup WM_KEYUP 17 -1071841279 PostMessage Drop
        Then
      Then
    GW_HWNDNEXT GetWindow
    Dup 0=3D Until
  Drop
  ;

The result of this word is that CodeWright is activated and
a 'v' is printed at the current cursor position.

The problem is that pressing Ctrl (17) is ignored.
I don't know how to determine what to put in lParam and have tried
to copy what keydown and keyup messages are sent to my own window.

Any suggestions are greatly appreciated.

Best Regards,
Morten A. Steien
Norsk Hydro IS-Partner

****************
MESSAGE 3
****************
From: Rick VanNorman [rvn_at_forth.com]
Sent: Tuesday, July 02, 2002 11:21 AM
To: Richard Owlett
Subject: [sftalk] Re: Replicating functionality of VisualBasic's
SendKeys command

Richard,

Tuesday, July 2, 2002, 10:31:41 AM, you wrote:

> I suspect that giving the appropriate window focus before calling this
> routine would have the desired effect. BUT I'm not sure. I would still
> have the problem of assuring that pseudo keystroke n would be
> completely processed before keystroke n+1.

The previous message partly answered this, but I send it before =
realizing
that it didn't specifically address this issue.

The answer lies in the use of SendMessage vs. PostMessage -- SendMessage
will wait for the receiving application to finish processing the message
(i.e., the character event) before returning; PostMessage will put the =
message
into the receiving application's message queue and return immediately.

SwiftForth uses the SendMessage technique to control the behavior of
NOTEPAD when no other editor is selected. It loads a file into notepad,
then sends "down arrow" commands via SendMessage to position the cursor
at whatever line is required.

Rick

****************
MESSAGE 2
****************
From: Rick VanNorman [rvn_at_forth.com]
Sent: Tuesday, July 02, 2002 11:17 AM
To: Richard Owlett
Subject: [sftalk] Re: Replicating functionality of VisualBasic's
SendKeys command

Hello Richard,

On Tuesday, July 2, 2002, 10:31:41 AM, you wrote:

RO> I've been doing more research and suspect the answer lies in an
RO> appropriate call to Keybd_Event.

The best way to do this is via the WM_KEYUP and WM_KEYDOWN messages, or
with the WM_CHAR message. Determine the handle of the window of the
target application using EnumWindows and matching for a window title,
then formulate and send the appropriate messages to the window with
SendMessage (or PostMessage). This is how Keybd_Event and the VB =
sendkeys
function work, except that they both take whatever is the active window
as their targets.

Look in the code that controls NOTEPAD in SwiftForth; in particular,
focus on NOTEPAD-GOTO-LINE FIND-NOTEPAD and NOTEPAD-LOCATOR .

Hope this helps,
Rick

****************
MESSAGE 1
****************
From: Richard Owlett [rowlett_at_atlascomm.net]
Sent: Tuesday, July 02, 2002 10:32 AM
To: sftalk_at_forth.com
Subject: [sftalk] Re: Replicating functionality of VisualBasic's
SendKeys command

I've been doing more research and suspect the answer lies in an
appropriate call to Keybd_Event.

Unfortunately all the examples I've found are for the current program
running in the 'current' widow which has focus.

I suspect that giving the appropriate window focus before calling this
routine would have the desired effect. BUT I'm not sure. I would still
have the problem of assuring that pseudo keystroke n would be
completely processed before keystroke n+1.

*****************************
PROBLEM STATEMENT
*****************************
Richard Owlett wrote:
>=20
> Cautionary note:
> The method of attack on the following problem may not ( and probably
> is not) the most efficient no matter what metric is applied. The
> PURPOSE of the problem is educational. If the driving force was
> "solving the problem", I would use Visual Basic and be done with it ;}
>=20
> Coarse general background:
> I find myself (drawn to) / ( entwined in ) transferring data between
> INCOMPATIBLE programs. In one case, the receiving program was
> EXPLICITLY designed to discourage ( they did think prohibit [chuckle]
> ) automatically loading data from a 'foreign' program [ actually they
> had a legitimate reason, but it conflicted with the user's ( my
> employer) needs ]. I did it anyway -- did someone say 'pipe' ?
>=20
> More specific background:
> The music director of my church wishes to display the verses of hymns
> on a screen.
> He has a PROPRIETARY program which searches a database and gives as
> output the selected verse(s) of the desired hymn with appropriate
> copywright information, generating the appropriate reports of using
> copywrited material to comply with ASCAP. [ We use that program
> EXPLICITLY for its reporting capability.]
>=20
> The displayable output PRESUMES the use of BRAVO.EXE ( for sake of {
> weak } arguement a Presentation Manager competitor ).
>=20
> MY PROBLEM backgound:
>=20
> Neither BRAVO nor PresentationManager gives an acceptable display.
> Using SwiftForth I can [ AND HAVE ] produce[d] an acceptable display.
>=20
> MY specific PROBLEM description:
> Using "Shell" and "SendKeys" under VisualBasic I can run BRAVO.EXE to
> produce a useable output file ( actually I've done it using Visual
> Basic for Applications under Word for Windows combuned with some Word
> macros).
>=20
> SPECIFIC PROBLEM DEFINITION:
> How do I send "specific 'keystrokes' " from SwiftForth to BRAVO to
> produce the desired output file which I already know how to process to
> give the desired result.
>=20
> I can launch BRAVO using ShellExecute.
> BUT, how do I send desired messages/keystrokes to it ?
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Mon Jan 31 2005 - 08:25:42 PST


Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!

This archive was generated 09-Feb-2012. Archive updated nightly.