How to send keystrokes to window that is not active

Share your macros, knowledge, solutions, services, ...
Post Reply
Petr
Posts: 106
Joined: Tue Oct 18, 2016 1:12 pm

How to send keystrokes to window that is not active

Post by Petr » Thu Nov 17, 2016 9:00 pm

In Windows it is not basically possible to send keystrokes to a window that is not active.
However, it is possible to make a window active while it does not overlap window that is currently
active and showing on top of other windows on the computer screen. The example here
activates "Notepad" window and sends "Hello Notepad!" text to it while the currently
active window is still showing on top and Notepad window does not overlap it.
The macro expects that Notepad is running.

Code: Select all

<cmds>

<#> Remeber what window is currently active
<varset>("vActiveWnd=_vActiveWindow_HWND","")

<#> Make the active window "always on top"
<winstate>("_vActiveWindow_HWND","ALWAYS_TOP")

<#> Activate Notepad window...
<actwin>("Notepad",0,0,"no")

<#> ... and send the keystrokes
<keys>Hello to Notepad!<cmds>

<#> Then activate the originaly active window again...
<actwin>("vActiveWnd",0,0,"no")

<#> ... and make it "not always on top"
<winstate>("vActiveWnd","NOT_ALWAYS_TOP")

Post Reply