Jump to content
Sign in to follow this  
Mochiza

How can I send keystrokes to an inactive window ?

Recommended Posts

Hello everyone, I'm trying to send the keystroke to an inactive notepad windows while the another one is activating. 

The problem that I found is word "Hello World" can't type in the inactive window, after I pressed the "Home" button while the cursor is staying in the active window.

 

 

Here is my code. I'm trying with 2 windows of Notepad, using ControlSend() and WinGetHandle().

HotKeySet("{PGUP}", "NotepadHWND")
HotKeySet("{HOME}", "Sim")
HotKeySet("{DEL}", "PrntResult")

Global $VAR_NotepadHWND

While 1
    Sleep(50)
WEnd

Func NotepadHWND()
    $VAR_NotepadHWND = WinGetHandle("[ACTIVE]")
EndFunc

Func Sim()
    Return ControlSend($VAR_NotepadHWND, "", "", "Hello World !!")
EndFunc

Func PrntResult()
    MsgBox(0, "","HWND is :" & $VAR_NotepadHWND)
EndFunc

Thank you everyone for sharing your solution and knowledge. 🤗

Capture.PNG

Share this post


Link to post
Share on other sites

LoL: inactive notepad !  Ok, how about you tell us what application you are trying to automate, and what is the goal of your issue...

Share this post


Link to post
Share on other sites
8 hours ago, Nine said:

LoL: inactive notepad !  Ok, how about you tell us what application you are trying to automate, and what is the goal of your issue...

I'm newbie for autoit and I just want to try this function with multiple copies of an application open which have the same title/text.

My purpose is typing some word to an inactive window while I'm in the active window. Refer to my code, press "PGUP" button to specify the window I want to send word to by using WinGetHandle() to identify. After that press "Home" button to call the function to send a word to inactive window by using ControlSend(). But my code not provides me the thing what I want.

 

I would like to say sorry if my description isn't clear for you. 

Share this post


Link to post
Share on other sites
16 hours ago, Mochiza said:

Func NotepadHWND()    

$VAR_NotepadHWND = WinGetHandle("[ACTIVE]")

EndFunc

wingethandle("[ACTIVE]") will return current active window handle (can return handle for another window than notebad ) ,so use this code instead

$VAR_NotepadHWND =WinGetHandle("[CLASS:Notepad]")

second , dont forget the Control ID in ControlSend so it should be :-

Func Sim()
    Return ControlSend($VAR_NotepadHWND, "", "Edit1"   , "Hello World !!")
                                           ;ControlID
EndFunc

 

Share this post


Link to post
Share on other sites
2 hours ago, Network_Guy said:

wingethandle("[ACTIVE]") will return current active window handle (can return handle for another window than notebad ) ,so use this code instead

$VAR_NotepadHWND =WinGetHandle("[CLASS:Notepad]")

second , dont forget the Control ID in ControlSend so it should be :-

Func Sim()
    Return ControlSend($VAR_NotepadHWND, "", "Edit1"   , "Hello World !!")
                                           ;ControlID
EndFunc

 

Now I can send the word to inactive window.

I have the question that if I don't know the "ControlID" or any properties of control (Id, ClassNN, ... ), so the word can't be sent to inactive window. Do we have the alternative ways to send the word to inactive window ?

Share this post


Link to post
Share on other sites

According to the help file: Send - Sends simulated keystrokes to the active window.
To send data to inactive windows you can either try to automate the GUI by using Control* functions or use COM to directly interact with the programs API and avoid the GUI.

It would help if you could tell us which program you REALLY try to automate at the end.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites
4 minutes ago, Nine said:

Use au3info.exe tool in autoit folder to find the control ID or any other properties.

There is no information about control.  (I try with RO exe)

sss.PNG

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...