Send commands to browser while Wordpad in focus Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Send commands to browser while Wordpad in focus

23 May 2023, 11:32

--------------------------------------------------------------------------------------------------------
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
The above is "F4" that opens, sizes and displays Wordpad atop Firefox window. The following is where my issue lies:

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
OK.... I have removed about 75% of my script, to keep focus, no pun intended, on just the issue I have described atop this post. There is zero question, that some of you will see a more efficient or cleaner way to do some actions here, but this is my level of knowledge.

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
I have tried this:

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
My goal is to key "PgDn" and send the mouse to chat box, paste / send text and return to Wordpad, where I can copy another LINK and repeat the process. If Wordpad must be minimized or even closed, that is fine. I will write the code necessary to do so, with each LINK sent. If you see something off, please ask... as I have butchered my script to limit what I am asking you to digest. Please be kind :xmas:

You will have questions, so fire away :morebeard:
Last edited by Evil-e on 25 May 2023, 00:02, edited 2 times in total.
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Send commands to browser while Wordpad in focus

23 May 2023, 15:53

Courtesy of wetware05 this work's for me when I have notepad++ open. Just take out or adjust what you need.Cheer's

Code: Select all

SetTitleMatchMode, 2
Process, Exist, firefox.exe
if !ErrorLevel = 0
{
    IfWinNotActive, ahk_exe firefox.exe,
    WinActivate, ahk_exe firefox.exe, 
    WinWaitActive, ahk_exe firefox.exe, 
 }
else
{
    Run, D:\PortableApps\FirefoxPortable\FirefoxPortable.exe
    WinWait, ahk_exe firefox.exe
 }

Sleep, 1500
Send, ^t
WinWaitActive,  Mozilla Firefox
Sleep, 200
ClipBoard:= "https://www.tvtv.ca/ns/halifax/luCAN-0002040-X"
Sleep 1000
Send, ^v
Send, {Enter}
Sleep, 4000
Send, ^{f}
Sleep, 2000
Send, SNE ; channel Name
Sleep, 200
Send, {Enter 2}
Return
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Send commands to browser while Wordpad in focus

23 May 2023, 19:23

@jrachr Thank you :thumbsup:

I have written this into my script after adapting my directories / file names and such:

Code: Select all

PgDn::                                                    ;paste text in chat (SEND)
keywait, PgDn
{
        BlockInput, On
        SetTitleMatchMode, 2
        Process, Exist, firefox.exe
        if !ErrorLevel = 0
        {
           Run, C:\Program Files\Google Chrome\+ Benjamin Boyce LINKS.rtf
           WinWait, ahk_class MozillaWindowClass
        }
           else
        {
           IfWinNotActive, ahk_class MozillaWindowClass  ;also tried "Mozilla Firefox". Chat box....
           WinActivate, ahk_class MozillaWindowClass     ;... title used other locations of script...
           WinWaitActive, ahk_class MozillaWindowClass   ;... that works correctly
        }
        Sleep, 1500
        WinWaitActive, ahk_class MozillaWindowClass
        Sleep 1000
        CoordMode, Mouse, Screen                         ;moves cursor to enter comment in chat
        MouseMove,1660,784,2
        sleep, 50
        send, ^v                                         ;pastes text in chat
        sleep, 250
        send {enter}                                     ;sends text in chat
        sleep, 50
        send {enter up}
        BlockInput, Off
}
return
Looking at the above, I was unsure if it would work. However, I have thought this with other scripts and sometimes they do :)

The above will launch my Wordpad file, but then the mouse locks up (hovering over out of focus Firefox window), but Ctrl+Alt+Delete releases it and continued to test. Once the mouse was free and Wordpad had focus, I copied some text, keyed "PgDn". Unfortunately, Wordpad remained in focus and PgDn scrolled down the text of Wordpad (to be expected)

If I key "F4", as I normally do, and manually copy a LINK I would share during a live steam and key "PgDn". Sadly, Wordpad remains in focus and cursor never moves. Manually apply focus to Firefox and my "PgDn" works as it always had.

My initial description verbalizes the problem, but I have used syntax which has, at times, thrown off those who offer assistance. I don't know how to describe differently, so hopefully this furthers understanding of my goal.

Thanks @jrachr for your providing assistance and if you have any additional thoughts, please share them :morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Send commands to browser while Wordpad in focus

24 May 2023, 03:05

Try removing bracket below pgdn. Also if your browser is chrome then your process would not be Firefox.exe it would be chrome.exe or whatever the name of the chrome process is. Same for the class settings. They wouldn't be Firefox they would be chrome. Just use window spy to find exactly what it is.
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Send commands to browser while Wordpad in focus

24 May 2023, 09:06

Good morning @jrachr ... My Wordpad file is located within the Chrome folder, but is Firefox I am using for chat input :D

Update on what I have found / learned. I have BOTH Chrome & Firefox running on separate parts of screen during all this, but Chrome is ONLY playing video / sound, so I don't interact with it at all. There are precisely 2 browsers that that have any success on YT and are Chrome V 49.0.2623.112 & Firefox v52.9.0. These are each about 8 years old, but no updates will run on my Win XP 32 bit machine. Chrome plays LIVE streams / audio, but chat box fails. Firefox will not play LIVE stream or audio, but chat box is fine. YT allows the chat box to "pop-out" as its own window, so I use AHK to manipulate Firefox chat box window along side Chrome video window to create the screen shot seen below :)

Wordpad is hovering over the Chrome window, so when it has focus FIrefox keymapping.exe loses all command of keyboard / mouse. When move mouse and click to bring Firefox into focus, my all of my input is done via keymapping_Firefox.exe and flawless. Chat box is in FF browser, so it's script is the one I use. Wordpad remains visible over Chrome window, but is of course now out of focus.

I have done LOTS of testing with AlwaysOnTop and as per the scuttlebutt some have said, some browsers do not yield to AlwaysOnTop commands and seems that Firefox is one of them. I have also tried a number of small applications found on interwebz that create "always on top" windows, but not found one that works.

When I use mouse to bring FF into focus, Wordpad remains visible, but falls out of focus, so all of my keystrokes / mouse input execute via AHK. If curious, I can post my full script, but it is quite a bit of information and to ask those who help to rummage through it for my specific tasks, is unnecessary :morebeard:

Screen-shot of what my script is automated to set-up for display on monitor. Wordpad in focus and neither script will function:
Image
Last edited by Evil-e on 24 May 2023, 10:09, edited 2 times in total.
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Send commands to browser while Wordpad in focus

24 May 2023, 13:38

Sorry Evil. Beyond my scope. I am running windows 11.Maybe someone can help. Cheer's
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Send commands to browser while Wordpad in focus

24 May 2023, 14:30

@jrachr ... I appreciate your efforts to help :D My Win XP 32b is ever creating issues and I would not have any of the above, if I was running at least a Win 8 64b system. I fell in love with XP since I began using it after my 1st OS... Millennium! Of course, I would have preferred an abacus to reach the final digit of pi, than use that OS any longer!

Buddy introduced me to Norton Ghost, so I became literally fearless with hacking even the most critical of system files. My XP is so insanely custom, so incredibly light-weight, so amazingly stable, that I had 3 100% brand-new machines built to run it, back in 2016. My limitations are the CPU, which are MASSIVE, by current standards, but I have almost 1400 games on it and the other 2 machines are updated my latest files every couple weeks.

OK, my arm is sore from patting myself on the back, so I am gonna go play one of those games now... :beer:

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Send commands to browser while Wordpad in focus  Topic is solved

24 May 2023, 23:51

--------------------------------------------------------------------------------------------------------
ALTERNATE SOLUTION. DIFFERS FROM GOAL STATED ABOVE, BUT FLAWLESS:
--------------------------------------------------------------------------------------------------------

@jrachr ... Well, not precisely what I was seeking, but a 100% perfect solution to my issue. I simply cut all of these scripts from my Chrome and Firefox AHK keymapping files and put them in "Keymapping_Benjamin_Boyce_LINKS_Chrome.exe". the "F4" key now just launches this keymapping file and now makes ZERO difference which browser or if Wordpad is in focus, the keys all work as though Firefox was in focus:

Code: Select all

sleep, 250
{
        Run, C:\Program Files\Google Chrome\+ Benjamin Boyce LINKS.rtf
        sleep, 250
        WinActivate, + Benjamin Boyce LINKS - WordPad ahk_class WordPadClass
        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
        WinGet, window, ID, A
	    TargetX := (A_ScreenWidth/2)-(Width/2)
	    TargetY := (A_ScreenHeight/2)-(Height/2)
        WinMove, ahk_id %window%, ,350 ,400 ,1000 ,600
        CoordMode, Mouse, Screen
        MouseMove,1000,600,0
}
#IfWinActive, ahk_class WordPadClass
DetectHiddenWindows, On
WinWait, ahk_class WordPadClass
WinWaitClose, ahk_class WordPadClass
ExitApp
home::                      ;paste "@" in chat allow highlight specific person (DO NOT SEND)
keywait, home
{
        BlockInput, On
        CoordMode, Mouse, Screen
        MouseMove,1660,1025,2
        sleep, 250
        send {LButton down}
        sleep, 50
        send {LButton up}
        CoordMode, Mouse, Screen
        MouseMove,1660,784,2
        sleep, 250
        send {LButton down}
        sleep, 50
        send {LButton up}
        CoordMode, Mouse, Screen
        MouseMove,1660,830,0
        sleep, 50
        ClipBoard:= "@"
        sleep, 50
        send, ^v
        BlockInput, Off
}
return
PgUp::                       ;paste text in chat allow editing (DO NOT SEND)
keywait, PgUp
{
        BlockInput, On
        CoordMode, Mouse, Screen
        MouseMove,1660,1025,2
        sleep, 250
        send {LButton down}
        sleep, 50
        send {LButton up}
        CoordMode, Mouse, Screen
        MouseMove,1660,784,2
        sleep, 250
        send {LButton down}
        sleep, 50
        send {LButton up}
        CoordMode, Mouse, Screen
        MouseMove,1660,830,0
        sleep, 50
        send, ^v
        BlockInput, Off
}
return
PgDn::                       ;paste text in chat (SEND)
keywait, PgDn
{
        BlockInput, On
        CoordMode, Mouse, Screen
        MouseMove,1660,1025,2
        sleep, 250
        send {LButton down}
        sleep, 50
        send {LButton up}
        CoordMode, Mouse, Screen
        MouseMove,1660,784,2
        sleep, 250
        send {LButton down}
        sleep, 50
        send {LButton up}
        CoordMode, Mouse, Screen 
        MouseMove,1660,830,0
        sleep, 50
        send, ^v
        sleep, 250
        send {enter}
        sleep, 50
        send {enter up}
        BlockInput, Off
}
return
Thought I would pass this along, just because I am totally jazzed :superhappy: :trollface: :bravo: :dance: :clap: I did the very closest next best thing to my stated goal above. This 100% resolves my issue, though it would be cool if one day I find a way to send these commands from out of focus window. Even as I am writing this, I am sure I could do this MUCH simpler in a couple ways, but no sense in working it out at this moment... lol

If plan to leave this as "unsolved", but if gregster or any mods take issue, drop me a DM and I will do so. Maybe one day someone will see it and offer another solution, that had not occurred to me. I will make a special edit in my OP, to let them know what is up.

:morebeard:

PS> I did need to add a few lines of code of "IfWinExist" and the like in each of my Chrome and Firefox main scripts, but easy-peasy ;)
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 257 guests