AHK script in the background

Get help with using AutoHotkey and its commands and hotkeys
ycheem
Posts: 10
Joined: 22 Jul 2020, 06:59

AHK script in the background

14 Sep 2020, 10:33

Hey I've figured out how to run a google chrome url and type things in it by doing

Code: Select all

run, urlgoeshere
although when I want to another tab like whatsapp web, it sends the keys in there. Is it possible for the script to be sent in one tab only without it interfering with other tabs?
User avatar
mikeyww
Posts: 1066
Joined: 09 Sep 2014, 18:38

Re: AHK script in the background

14 Sep 2020, 10:41

Although the Run command tends to open a new tab when used with a Web browser, you can do an easy workaround if you would like to avoid opening a new tab (other than finding a browser plugin that does that).

1. Activate the browser window.

2. Send !d to focus on the address bar.

3. Send the URL.

Browsers sometimes also need to be configured to avoid opening a new tab when a new address is entered into the address bar.
ycheem
Posts: 10
Joined: 22 Jul 2020, 06:59

Re: AHK script in the background

14 Sep 2020, 10:43

would this solution allow the script to only type in the focused tab as I'd like to use whatsapp without it typing in whatsapp's tab?
Last edited by ycheem on 14 Sep 2020, 10:45, edited 1 time in total.
ycheem
Posts: 10
Joined: 22 Jul 2020, 06:59

Re: AHK script in the background

14 Sep 2020, 10:49

ah I see you've misinterpreted what i mean lol. The problem isn't that it continuously opens the url or anything, the problem is that it types in the wrong tab. I can't seem to figure out how focus it typing on one specific tab even though I'm typing in another
User avatar
mikeyww
Posts: 1066
Joined: 09 Sep 2014, 18:38

Re: AHK script in the background

14 Sep 2020, 10:58

The only code you provided is the Run command, and that does not type anything.

If you are typing in your Web browser, you won't want Run to execute while you are typing.

Some Web sites do enable URLs that post data to one of its forms (e.g., Web search sites). That would work while you are typing if the Web site enables it.
ycheem
Posts: 10
Joined: 22 Jul 2020, 06:59

Re: AHK script in the background

14 Sep 2020, 11:11

My bad, I'll post an example code of what im doing then if that clear it up. Now the thing is that if i have to go over to whatsapp's textbox it'd start typing owo there when it should be typing owo in the other tab's textbox only while I'm typing a different message in whatsapp.

Code: Select all

Run, urlcomeshere
1:: 
loop
{ 
  Send,owo
  Sleep 100 
  Send {enter}
  } 
  Return 
  
  3::pause
User avatar
mikeyww
Posts: 1066
Joined: 09 Sep 2014, 18:38

Re: AHK script in the background

14 Sep 2020, 11:23

1. You generally will not want AHK to issue Send commands while you are actively typing something different. The text will get jumbled.

2. If you need to wait until the new tab is active, you can issue WinWaitActive. Use the browser tab's title as the window title. That works in most cases.
ycheem
Posts: 10
Joined: 22 Jul 2020, 06:59

Re: AHK script in the background

14 Sep 2020, 11:28

How do I go about using winwaitactive if I'm using different google tabs or windows?
would I just do:

Code: Select all

Winwaitactive, tabname - Google Chrome
User avatar
mikeyww
Posts: 1066
Joined: 09 Sep 2014, 18:38

Re: AHK script in the background

14 Sep 2020, 11:31

Try it and see.

But if you wish, you can truncate the window title's text in your command. As long as your text matches the window's leading text, there is a match. Thus, you don't really need the browser's name at the end unless you have multiple browsers running and want to be specific.

Code: Select all

WinWaitActive, tabname,, 4
If ErrorLevel
 MsgBox, 48, Error, No tabs here!

Return to “Ask For Help”

Who is online

Users browsing this forum: ader5429, Bing [Bot], Google [Bot], mouseman82, Pavel, Redbird, Xtra and 32 guests