EDIT: POST #8 HAS ALTERNATE SOLUTION. I AM STILL INTERESTED IF THE FOLLOWING CAN BE DONE:
--------------------------------------------------------------------------------------------------------
Possible limitations: AHK v1.1.30.3
Windows XP SP3 32bit
GOAL: AHK_Firefox.exe to accept commands while Wordpad is in focus. To close or minimize Wordpad is OK, but minimize preferred
I moderate a couple channels on YT, so use "F4" to launch Wordpad for LINKS I regularly share in chat box. When Wordpad is launched, it runs atop and steals focus from Firefox browser, so my AHK.exe file no longer has control of keyboard / mouse input. I have tried ControlSend, ControlFocus, WinActive, IfWinExist and the like. If I manually close or minimize Wordpad, focus returns to Firefox and no issues at all. However, my preference would be to key "PgDn" which will navigate to chat box, paste text and send, but will not do so with Wordpad in focus. I have a number of LINKS and info the creators want me to share each live stream, so would want to avoid minimizing / normal window Wordpad repeatedly for each copy / paste performed:
This is my firefox script, with all unrelated code removed, so easier to focus on my issue. I may have missed something, so ask if does not make sense:
Code: Select all
sleep, 250
Run, C:\Program Files\Firefox\Firefox.exe
#SingleInstance Force ;reloads Firefox browser or launches blank tab when chat box is open
#IfWinActive, ahk_exe Firefox.exe
DetectHiddenWindows, On
WinWait, ahk_exe Firefox.exe
WinWaitClose, ahk_exe Firefox.exe
ExitApp
return
ControlFocus, OK, ahk_class MozillaWindowClass ;forces focus of Firefox browser when cursor is active in its window
F4:: ;"Tap" opens + Benjamin Boyce LINKS "Hold" closes file
keywait,F4,t.2 ;"Hold" 200ms will close file when focus on browser window
if (errorlevel) {
ControlSend, + Benjamin Boyce LINKS - WordPad ahk_class WordPadClass ;sends commands "+ Benjamin Boyce LINKS.rtf" while out of focus
sleep, 250
WinMaximize, + Benjamin Boyce LINKS - WordPad ahk_class WordPadClass ;maximizes "+ Benjamin Boyce LINKS.rtf" while out of focus
sleep, 250
WinClose, + Benjamin Boyce LINKS - WordPad ahk_class WordPadClass ;closes "+ Benjamin Boyce LINKS.rtf" after setting Wordpad to open fullscreen
sleep, 250
CoordMode, Mouse, Screen ;moves cursor near center of the screen
MouseMove,1000,600,0
} else {
Run, "C:\Program Files\Google Chrome\+ Benjamin Boyce LINKS.rtf", ,Min ;launches "+ Benjamin Boyce LINKS.rtf" minimized to system tray
sleep, 250
WinActivate, + Benjamin Boyce LINKS - WordPad ahk_class WordPadClass ;sets as active window
sleep, 50
WinActivate, + Benjamin Boyce LINKS - WordPad ahk_class WordPadClass
sleep, 50
WinActivate, + Benjamin Boyce LINKS - WordPad ahk_class WordPadClass
sleep, 50
WinWaitActive, + Benjamin Boyce LINKS - WordPad ahk_class WordPadClass ;sets this window to apply following script
WinGet, window, ID, A
TargetX := (A_ScreenWidth/2)-(Width/2) ;sets horizontal target for window as 1/2 of screen width
TargetY := (A_ScreenHeight/2)-(Height/2) ;sets horizontal target for window as 1/2 of screen hight
WinMove, ahk_id %window%, ,400 ,400 ,1000 ,600 ;window position: from LH side , from top , width , hight
CoordMode, Mouse, Screen ;moves cursor near center "+ web site log-in and passwords.rtf"
MouseMove,1000,600,0
} ;sets chat to accept keyboard input
return
Code: Select all
PgDn:: ;paste text in chat (SEND)
keywait, PgDn
{ ;Firefox window active so its keymapping is in control of script
BlockInput, On
MouseMove,1660,830,0 ;this is chat text input location
sleep, 50
send, ^v
sleep, 250
send {enter}
sleep, 50
send {enter up}
BlockInput, Off
}
return
I have tried, but not limited to, the following:
Code: Select all
PgDn:: ;paste text in chat (SEND)
keywait, PgDn
{
BlockInput, On
WinActivate, ahk_class MozillaWindowClass
sleep, 50
WinActivate, ahk_class MozillaWindowClass
sleep, 50
WinActivate, ahk_class MozillaWindowClass
sleep, 50
WinWaitActive, ahk_class MozillaWindowClass
WinGet, window, ID, A
MouseMove,1660,830,0 ;this is chat text input location
sleep, 50
send, ^v
sleep, 250
send {enter}
sleep, 50
send {enter up}
BlockInput, Off
}
return
Code: Select all
PgDn:: ;paste text in chat (SEND)
keywait, PgDn
{
BlockInput, On
ControlSend, ahk_class MozillaWindowClass :tried "ControlFocus" "IfWinExist ahk_class MozillaWindowClass"
sleep, 250
WinActivate, ahk_class MozillaWindowClass ;tried all of these with / without these activate lines and Wordpad file itself as well
sleep, 50
WinActivate, ahk_class MozillaWindowClass
sleep, 50
WinActivate, ahk_class MozillaWindowClass
sleep, 50
WinWaitActive, ahk_class MozillaWindowClass
WinGet, window, ID, A
MouseMove,1660,830,0 ;this is chat text input location
sleep, 50
send, ^v
sleep, 250
send {enter}
sleep, 50
send {enter up}
BlockInput, Off
}
return
Code: Select all
PgDn:: ;paste text in chat (SEND)
keywait, PgDn
{
BlockInput, On
ControlSend, WordPad ahk_class WordPadClass :tried "ControlFocus" "IfWinExist ahk_class MozillaWindowClass"
sleep, 250
WinActivate, WordPad ahk_class WordPadClass ;tried all of these with / without these activate lines and Wordpad file itself as well
sleep, 50
WinActivate, WordPad ahk_class WordPadClass ;tried every combination of browser / Wordpad WindowSpy title here
sleep, 50
WinActivate, WordPad ahk_class WordPadClass
sleep, 50
WinWaitActive, ahk_class MozillaWindowClass
WinGet, window, ID, A
MouseMove,1660,830,0 ;this is chat text input location
sleep, 50
send, ^v
sleep, 250
send {enter}
sleep, 50
send {enter up}
BlockInput, Off
}
return
![Happy holidays! :xmas:](./images/smilies/xmas.gif)
You will have questions, so fire away
![Behold the awsomeness of my beard. You are jelly. :morebeard:](./images/smilies/morebeard.png)