[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Sending keys.

Posted on 1999-12-23
11
Medium Priority
?
156 Views
Last Modified: 2010-05-02
How would I send keys to another window that I know the name of?
i.e. - - -
In programA there is a command buttton that when you click it, it will open another program(programB). On that window there is a command button.  How would I make programA be able to push the button on programB using sendkeys?
0
Comment
Question by:master01
11 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2304615
To set focus to ProgramA, use:

   AppActivate "title"

Once you have done that, do:

   SendKeys "{TAB}",TRUE

until the command button if focused.  For example, when you start ProgramA, if you have to hit the tab 4 times before the command button is selected, then you need to do the sendkeys 4 times...


Once you have focus on the command button, do this:

   SendKeys " ",TRUE

This will "press" the button...


Cheers!
0
 

Author Comment

by:master01
ID: 2304645
But how would I do it if the windows title varies between 2 names "Send Online Message" and "Send Offline Message" ?
0
 

Author Comment

by:master01
ID: 2304666
How would I do it though if the title of the window can be either "Send Online Message" or "Send Offline Message"?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 30

Expert Comment

by:Axter
ID: 2304768
Do a AppActivate to both.

AppActivate "Send Online Message"
AppActivate "Send Offline Message"

No matter which window is open, it will switch to it.
0
 

Author Comment

by:master01
ID: 2304824
Yes, but then I get an error because there is no AppActivate with the other name.
0
 
LVL 1

Expert Comment

by:phiro
ID: 2304981
Catch the error (5) and resume next...
Not too clean, but functional.
Another way would be to use the WINAPI calls.
With Findwindow
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

You can search for your window. If this window does not exist, the returnvalue will be 0 otherwise, the handle to your window is returned. You would not need that, you can assess the existence of your window with FindWindows and use AppActivate when is does.

Example :
in a form with a label1, text1 and a command1 put in the following code :
Option Explicit

Private sAppToFind As String

Private Sub Command1_Click()
    Dim l_hWnd As Long
   
    'sAppToFind = String(Len(sAppToFind), 0)
    sAppToFind = Text1.Text
    'sAppToFind = Trim(sAppToFind)
    l_hWnd = FindWindow(vbNullString, sAppToFind)
    If l_hWnd <> 0 Then
        AppActivate sAppToFind
    Else
        MsgBox "No such window"
    End If
End Sub
' ********END FORM*************
In a module add the code:

Option Explicit

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

' *******END MODULE *************



0
 
LVL 14

Expert Comment

by:mcrider
ID: 2305416
master01,

In your question, you SPECIFICALLY asked:

  "How would I send keys to another window that I know the name of?"

I gave you the correct valid answer using native VB commands.  Rejecting the correct answer and asking a different question is not really fair...

:-(
0
 

Author Comment

by:master01
ID: 2305467
You are right mcrider.  please just post any answer and you can have your points.  Sorry for the misunderstanding people.
0
 
LVL 14

Accepted Solution

by:
mcrider earned 200 total points
ID: 2305525
Posting for points...

Thanks for playing fair!


Cheers!
0
 

Author Comment

by:master01
ID: 2305692
Sorry for the misunderstanding.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2306027
Thanks for the points!

Merry Christmas!

Cheers!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

640 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question