Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
BannerStore
Posts: 87
Joined: 06 Sep 2017, 19:29

Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by BannerStore » 28 Jan 2020, 16:33

Script's Functions
With Windows 10, you can select an option in which you can scroll an inactive window as long as you hover over it. This really makes life easier. I want to take this a step farther and have other commands sent to this inactive window.

For example, I have an AutoHotkey script which allows me to scroll active windows much more quickly when I hold down the shift button. It would be nice if I could use the same shift button when scrolling an inactive window. Instead, I can only scroll slowly with inactive windows and it's a pain.
Another example is it would be super-nice to move forward and backward in Chrome without clicking on the webpage. It may not seem like a big deal to click on the window first but it's inconvenient because you occasionally accidentally click on a link on the webpage and you are sent to somewhere you didn't want to go.

My Programming Experience
So, I'm trying to create a script that allows me to activate a range of hotkeys with certain inactive windows as long as I am currently hovering over the window. I looked everywhere and I can't seem to find anyone else having created a similar script. (If you have one, please send me the link!!!) So, I resigned myself to writing it even though I am BAD at programming. I just learned about AutoHotkey about a month ago and I don't have any programming experience!

How the Script Works
The program is first set up so that a function (MouseIsOver) retrieves the window's id that my mouse is currently hovering over. Within the same function, it also retrieves the active window's id. I put this function at the bottom of the script which apparently is the programming norm in AutoHotkey. (Shouldn't it be better at the top so you know what functions do inside the script? No big deal.)

Then, the script starts with an "if or else" statement. If the hovered window's id is the same as the active window, then nothing happens. However, if the window's id is NOT the active window, then I wrote a long list of hotkeys that will be intercepted before they go to the active window and will be sent directly to the window the mouse is hovering instead. I made it so the script only works on Chrome, Autohotkey scripts, Windows, Excel, Directory Opus, and File Explorer windows. I'd rather have the hotkeys be sent to the active window in other cases.

Below is the finished script I have written. For some reason, when I try to run the script, AutoHotkey states that there is something wrong with the If and Else statements. I can't figure out what's wrong. I tried many different ways to write it. This is why I had to make a separate #If Else statement for each type of window and paste and copy the same list of hotkeys I want to send. This script would be much shorter otherwise.

Once you, guys can tell me what's wrong with the if and else statements, I'm sure there will be a ton more errors that will follow. Can you guys make any other obvious suggestions to make this work? Remember I'm a total newbie so I might not know some really basic stuff that most people here know.

Code: Select all

;				         	           	    COMMANDS SENT TO HOVERED WINDOWS
;
;                                               AUTOEXECUTE SECTION
;==================================================================================================================
#NoTrayIcon         	; Removes this script's AutoHotkey icon in the notification area.  Icon is unnecessary.
#Persistent				; Ensures this script will always be running in the background.  Never stops.
#SingleInstance force  	; Only one instance of this script will be allowed to run at a time.
#NoEnv 					; Environmental variables are all disabled here so no need to verify if a string is one.
#Warn, UseUnsetLocal  	; For debugging, error-prone with some variables. Warning on uninitialized variables.
SendMode Input  		; Send (aka SendEvent) changed to SendInput which is a faster and more reliable command.
SetBatchLines,-1		; Run script at maximum speed.
Return

;Legend:            	+	=	shift
;						^	=	control
;						! 	= 	alt
;						#	=	windows key



;                              		        SCRIPT(S) SECTION
;==================================================================================================================


#If MouseIsOver(AWinTitle)

#Else If MouseIsOver(ahk_class OpusApp)							; Hotkeys for Word (I'd like to use "OR" to connect all the
{															    ; programs instead of rewriting the same exact hotkeys for
	^Tab:: ControlSend,, ^{Tab}, WinTitle						; all the programs but I can't don't know how to use "OR").
	^+Tab:: ControlSend,, ^{Tab}, WinTitle						; I tried to add it but the script came up with an error.
	XButton1:: ControlSend,, ^{XButton1}, WinTitle
	XButton2:: ControlSend,, ^{XButton2}, WinTitle
	^w:: ControlSend,, ^w, WinTitle
	Alt & F4:: ControlSend,, {Alt}{F4}, WinTitle
	^n:: ControlSend,, ^n, WinTitle
	LShift::
	While GetKeyState("LShift", "P")
		ControlSend,, {Shift Down}, WinTitle
	Return

}
#Else If MouseIsOver(ahk_class XLMain)							; Hotkeys for Excel
{
	^Tab:: ControlSend,, ^{Tab}, WinTitle
	^+Tab:: ControlSend,, ^{Tab}, WinTitle
	XButton1:: ControlSend,, ^{XButton1}, WinTitle
	XButton2:: ControlSend,, ^{XButton2}, WinTitle
	^w:: ControlSend,, ^w, WinTitle
	Alt & F4:: ControlSend,, {Alt}{F4}, WinTitle
	^n:: ControlSend,, ^n, WinTitle
	LShift::
	While GetKeyState("LShift", "P")
		ControlSend,, {Shift Down}, WinTitle
	Return
	
}
#Else If MouseIsOver(ahk_class dopus.lister)						; Hotkeys for Directory Opus
{ 
	^Tab:: ControlSend,, ^{Tab}, WinTitle
	^+Tab:: ControlSend,, ^{Tab}, WinTitle
	XButton1:: ControlSend,, ^{XButton1}, WinTitle
	XButton2:: ControlSend,, ^{XButton2}, WinTitle
	^w:: ControlSend,, ^w, WinTitle
	Alt & F4:: ControlSend,, {Alt}{F4}, WinTitle
	^n:: ControlSend,, ^n, WinTitle
	LShift::
	While GetKeyState("LShift", "P")
		ControlSend,, {Shift Down}, WinTitle
	Return
	
}
#Else If MouseIsOver(ahk_class Chrome_WidgetWin_1)					; Hotkeys for Chrome
{
	^Tab:: ControlSend,, ^{Tab}, WinTitle
	^+Tab:: ControlSend,, ^{Tab}, WinTitle
	XButton1:: ControlSend,, ^{XButton1}, WinTitle
	XButton2:: ControlSend,, ^{XButton2}, WinTitle
	^w:: ControlSend,, ^w, WinTitle
	Alt & F4:: ControlSend,, {Alt}{F4}, WinTitle
	^n:: ControlSend,, ^n, WinTitle
	LShift::
	While GetKeyState("LShift", "P")
		ControlSend,, {Shift Down}, WinTitle
	Return
	
}
#Else If MouseIsOver(ahk_class AutoHotkeyGUI)					; Hotkeys for AutoHotkey
{
	^Tab:: ControlSend,, ^{Tab}, WinTitle
	^+Tab:: ControlSend,, ^{Tab}, WinTitle
	XButton1:: ControlSend,, ^{XButton1}, WinTitle
	XButton2:: ControlSend,, ^{XButton2}, WinTitle
	^w:: ControlSend,, ^w, WinTitle
	Alt & F4:: ControlSend,, {Alt}{F4}, WinTitle
	^n:: ControlSend,, ^n, WinTitle
	LShift::
	While GetKeyState("LShift", "P")
		ControlSend,, {Shift Down}, WinTitle
	Return
	
}
#Else If MouseIsOver(ahk_class CabinetWClass)					; Hotkeys for File Explorer
{
	^Tab:: ControlSend,, ^{Tab}, WinTitle
	^+Tab:: ControlSend,, ^{Tab}, WinTitle
	XButton1:: ControlSend,, ^{XButton1}, WinTitle
	XButton2:: ControlSend,, ^{XButton2}, WinTitle
	^w:: ControlSend,, ^w, WinTitle
	Alt & F4:: ControlSend,, {Alt}{F4}, WinTitle
	^n:: ControlSend,, ^n, WinTitle
	LShift::
	While GetKeyState("LShift", "P")
		ControlSend,, {Shift Down}, WinTitle
	Return
	
}
#Else
Return


MouseIsOver(WinTitle) {											; Function that retrieves the active and inactive window's ID's
	MouseGetPos,,, Win
	WinActive(AWinTitle)
	return WinExist(WinTitle . " ahk_id " . Win)
}

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by boiler » 28 Jan 2020, 23:12

Primary issues:
While #If directives do apply to hotkeys, there is no associated #Else directive. You just start another #If section to apply to the hotkeys below it until another #If is encountered. Do not confuse If and Else with #If (and non-existent #Else).

A literal string in a function parameter needs quotes around it because it uses expression syntax, so MouseIsOver(ahk_class OpusApp) would be MouseIsOver("ahk_class OpusApp").

So this line:

Code: Select all

#Else If MouseIsOver(ahk_class OpusApp)
would become:

Code: Select all

#If MouseIsOver("ahk_class OpusApp")
Lines such as ^Tab:: ControlSend,, ^{Tab}, WinTitle will not work for a couple reasons. One is that WinTitle in this case would need to be %WinTitle% to pass the value of the variable WinTitle instead of the literal text "WinTitle". That's because in this case, it is using legacy syntax, not expression syntax (see here and here). The other reason is that the variable WinTitle did not inherit the value of the variable from the MouseIsOver function because it is local to that function. More on that here.

There are other issues, but that's probably plenty to chew on for a while. Good luck on your journey. You're making a good start.

BannerStore
Posts: 87
Joined: 06 Sep 2017, 19:29

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by BannerStore » 02 Feb 2020, 20:01

For people who don't know, this is a script that sends hotkeys, NOT to the active window, but to the inactive window which the mouse is hovering over. This is a really helpful script because there are so many times, you don't want to activate the window, you just want to send hotkeys to it.

For example, if you are scrolling an inactive website page and you want to use shift to make it scroll faster (I have it set up that shift makes it scroll by pages). Another example is that you are over a couple of websites and you want to tab through them but the window is not active. You don't have to click it with your mouse to activate it first. It really saves a lot of time.

By the way, thank you for your help. It helped tremendously. As you can see, I reworked the entire script. I spent tons of hours doing what you suggested and researching the subjects that you suggested. I figured out what I did wrong and fixed the mistakes. I simplified the code so it would be much easier to discuss it over.

Now, I'm at the point in the script where I am at a dead-end again. I can't figure out why it's not working from this point on. If you could help, that would be fantastic.

At this point, I can't figure out what's wrong. This is the simplified code:

Code: Select all

#Persistent			
#SingleInstance force  	
SendMode Input
Return
Global OverWinID

#If (MouseIsOver("Chrome_WidgetWin_1")) and (!WinActive, ahk_id %OverWinID%)		; If the mouse is hovering over a Chrome window and it's not the active window, then  
	^Tab:: ControlSend,, ^{Tab}, "ahk_id %OverWinID%"							; Send these hotkeys to the Chrome window instead of the active window.
	^+Tab:: ControlSend,, ^+{Tab}, "ahk_id %OverWinID%"						

MouseIsOver(WinTitle) {													; This function retrieves the active and inactive window IDs as well as the active window's class to use in the above #If statement
	MouseGetPos,,, OverWinID
	WinGetClass, OverWinClass, ahk_id %OverWinID%
	Return WinTitle=OverWinClass	
}
Return


^F12::MsgBox Test: OverWinID = %OverWinID%
^F11::
{
Test:=(!WinActive, ahk_id %OverWinID%)
MsgBox %test%
}
*The bottom hotkeys are only test messageboxes to see what the global variables are.

1. I designated OverWinID as a global variable at the top so that it can work in the MouseIsOver function as well as in the #If statement.

2. I fixed the little things like putting quotes in the MouseIsOver function and putting the variable within % %.

I totally reworked the code and got it working so now it reaches the first line in the #If statement. But, it's here where I think I am stuck. The problem might be the ControlSend. Is it expressed properly?

I want the hotkey sent to the inactive window instead of the active window. But, it doesn't seem like my hotkeys are being sent to the inactive window that my mouse is hovering over. It also isn't sending them to the active window either. When I press the hotkeys, it doesn't seem to be doing anything. So, I have no idea where the hotkeys are being sent.

Is the ControlSend function written out correctly?

Is there anything that you can find immediately wrong?

Does an #If statement with hotkeys have to end with a sole "#If" at the end before the function?

Again, thanks for any help that you can provide. Or, anyone else for that matter. I'd greatly appreciate it.



boiler wrote:
28 Jan 2020, 23:12
Primary issues:
While #If directives do apply to hotkeys, there is no associated #Else directive. You just start another #If section to apply to the hotkeys below it until another #If is encountered. Do not confuse If and Else with #If (and non-existent #Else).

A literal string in a function parameter needs quotes around it because it uses expression syntax, so MouseIsOver(ahk_class OpusApp) would be MouseIsOver("ahk_class OpusApp").

So this line:

Code: Select all

#Else If MouseIsOver(ahk_class OpusApp)
would become:

Code: Select all

#If MouseIsOver("ahk_class OpusApp")
Lines such as ^Tab:: ControlSend,, ^{Tab}, WinTitle will not work for a couple reasons. One is that WinTitle in this case would need to be %WinTitle% to pass the value of the variable WinTitle instead of the literal text "WinTitle". That's because in this case, it is using legacy syntax, not expression syntax (see here and here). The other reason is that the variable WinTitle did not inherit the value of the variable from the MouseIsOver function because it is local to that function. More on that here.

There are other issues, but that's probably plenty to chew on for a while. Good luck on your journey. You're making a good start.

BannerStore
Posts: 87
Joined: 06 Sep 2017, 19:29

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by BannerStore » 02 Feb 2020, 20:54

Wait!

I just noticed while changing hotkeys around, that for ControlSend, you can't send the same hotkey that triggered the ControlSend!!

If this is true, how do you get around this????

Can anyone help?

gregster
Posts: 8988
Joined: 30 Sep 2013, 06:48

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by gregster » 02 Feb 2020, 21:44

Is it? Consider ^a::ControlSend, , ^a, ahk_exe Notepad.exe.

Btw, this looks wrong; ^Tab:: ControlSend,, ^{Tab}, "ahk_id %OverWinID%"
Why quotation marks?

#If (MouseIsOver("Chrome_WidgetWin_1")) and (!WinActive, ahk_id %OverWinID%)
There is a WinActive() function, but you don't use it.

There is no Winactive command; there is the IfWinActive command, but it can't be used in expressions.
So, use the function version - and syntax instead.

BannerStore
Posts: 87
Joined: 06 Sep 2017, 19:29

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by BannerStore » 03 Feb 2020, 15:30

Gregster,

You're completely right. Ah...I messed up there. I thought that WinActive would return a false or negative but I now know it returns the unique ID instead. Oops. It's hard to keep track of what all these functions and commands do, especially for a person who's never programmed before.

With respect to the quotation markets around ahk_ID %OverWinID%, I initially tried without the quotation marks but since that didn't work, I tried it with quotation marks. I've been trying every possible thing that could be wrong with it. Thus, the many hours it's taking to write this script!

I still can't get hotkeys sent to the hovering window. This is what I have so far. I use ^F10 as a test and it works when I hover the mouse over the inactive window. But, it seems like ControlSend won't send the hotkeys to the inactive Chrome page. Is it because I have to specify a control area? (I tried this but didn't seem to work.)

What can I do to make ControlSend work with inactive windows?

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by boiler » 03 Feb 2020, 16:11

BannerStore wrote: You're completely right. Ah...I messed up there. I thought that WinActive would return a false or negative but I now know it returns the unique ID instead. Oops. It's hard to keep track of what all these functions and commands do, especially for a person who's never programmed before.
It can be treated as if it's returning true or false because it will return a unique ID, which will be interpreted as true, or 0, which will be interpreted as false. What Gregster was pointing out was that you didn't even use the function. You were using the command version as if it were a function. So instead of this:
#If (MouseIsOver("Chrome_WidgetWin_1")) and (!WinActive, ahk_id %OverWinID%)
...it would be this:
#If (MouseIsOver("Chrome_WidgetWin_1")) and (!WinActive("ahk_id " OverWinID))
BannerStore wrote: With respect to the quotation markets around ahk_ID %OverWinID%, I initially tried without the quotation marks but since that didn't work, I tried it with quotation marks. I've been trying every possible thing that could be wrong with it. Thus, the many hours it's taking to write this script!
See my version above. You don't use % signs in expressions (not typically, and not for what you will be doing yet), and you don't put the variable name inside the quotes either. Read about it in the expressions link in Gregster's post.
BannerStore wrote: I still can't get hotkeys sent to the hovering window. This is what I have so far. I use ^F10 as a test and it works when I hover the mouse over the inactive window. But, it seems like ControlSend won't send the hotkeys to the inactive Chrome page. Is it because I have to specify a control area? (I tried this but didn't seem to work.)

What can I do to make ControlSend work with inactive windows?
Even once you get all the syntax correct, using ControlSend won't work with all windows. You should always test with a very simple script to see if the window you are targeting is receptive to receiving what you send to it when it's inactive.

BannerStore
Posts: 87
Joined: 06 Sep 2017, 19:29

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by BannerStore » 03 Feb 2020, 19:07

Boiler,

Thanks for the helpful suggestions. I took your suggestions. I changed the WinActive command to something else before I saw your post. Both ways work I guess.

Code: Select all

Global OverWinID, AWinID, OverWinTitle, AWinTitle
Return

#If (MouseIsOver("Chrome_WidgetWin_1")) and (AWinTitle != OverWinTitle)							; If the mouse is hovering over a Chrome window AND it's not the active window, then  
^w::ControlSend, , ^w, ahk_id %OverWinID%
#If


MouseIsOver(WinTitle) {													; This function retrieves the active and inactive window IDs as well as the active window's class to use in the above #If statement
	MouseGetPos,,, OverWinID
	AWinID:=WinActive(A)
	WingetTitle, AWinTitle, A
	WinGetTitle, OverTitle, ahk_id %OverWinID%
	WinGetClass, OverWinClass, ahk_id %OverWinID%
	Return WinTitle=OverWinClass	
}
Return
I tested this and it works in that when I put my cursor over a Chrome window that's not activated, it will try to do what I tell it. And, if I move it away from the Chrome page, it stops. (I tested by putting in a message box.)

The only problem now is to figure out why ControlSend doesn't work. Control Tab and Control Shift-Tab never worked but Control w started working for about a minute! Then I moved things around and it doesn't work anymore. :crazy:

Can anyone think of what I can do to make it work? It would be cool to send hotkeys to inactive windows just like you can scroll inactive Chrome pages. For example, as I'm scrolling inactive Chrome pages, I always press shift to scroll faster (I've made shift into a hotkey that enables 1-page scrolling. It's annoying to click the window and try to scroll again.

But, there are so many other uses for this. You can go through Chrome tabs without activating it. You can navigate Excel worksheets and workbooks to look for the data that you're looking for. I wish I could make this work!

If ControlSend doesn't work for inactive windows, what other significant, practical use would it have?

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by boiler » 03 Feb 2020, 19:26

BannerStore wrote:
03 Feb 2020, 19:07
If ControlSend doesn't work for inactive windows, what other significant, practical use would it have?
That is the purpose, but you missed a key point of what I said. It works for some windows, but it doesn't work for all windows. That's not the fault of the command or of AHK in general. If a program is written so that it only accepts keystrokes when it's the active window, then there's not much you can do about it short of hacking the code for that program.

By the way, in your MouseIsOver function, you have made something that should be totally contained in the function to instead use global variables and require a compound conditional statement outside the function using some of its variables. The check to see if AWinTitle != OverWinTitle can and should happen within the function itself, which would allow you just to check MouseIsOver instead of MouseIsOver and AWinTitle != OverWinTitle (and not require them to be global). So it would be like this:

Code: Select all

Global OverWinID, AWinID
Return

#If (MouseIsOver("Chrome_WidgetWin_1"))						; If the mouse is hovering over a Chrome window AND it's not the active window, then  
^w::ControlSend, , ^w, ahk_id %OverWinID%
#If


MouseIsOver(WinTitle) {													; This function retrieves the active and inactive window IDs as well as the active window's class to use in the above #If statement
	MouseGetPos,,, OverWinID
	AWinID:=WinActive(A)
	WingetTitle, AWinTitle, A
	WinGetTitle, OverTitle, ahk_id %OverWinID%
	WinGetClass, OverWinClass, ahk_id %OverWinID%
	Return (WinTitle=OverWinClass) and (AWinTitle != OverWinTitle)
}
Return

BannerStore
Posts: 87
Joined: 06 Sep 2017, 19:29

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by BannerStore » 04 Feb 2020, 17:02

boiler,

I actually got your point but I was just grousing how it wasn't working for Chrome. Anyway, I tried to make it work for Word and it didn't seem to work for Word either. Once I get the time, I'll try other programs. But, thanks for the help.

By the way, why is it important to make the condition written in the function rather than the If statement?


boiler wrote:
03 Feb 2020, 19:26
BannerStore wrote:
03 Feb 2020, 19:07
If ControlSend doesn't work for inactive windows, what other significant, practical use would it have?
That is the purpose, but you missed a key point of what I said. It works for some windows, but it doesn't work for all windows. That's not the fault of the command or of AHK in general. If a program is written so that it only accepts keystrokes when it's the active window, then there's not much you can do about it short of hacking the code for that program.

By the way, in your MouseIsOver function, you have made something that should be totally contained in the function to instead use global variables and require a compound conditional statement outside the function using some of its variables. The check to see if AWinTitle != OverWinTitle can and should happen within the function itself, which would allow you just to check MouseIsOver instead of MouseIsOver and AWinTitle != OverWinTitle (and not require them to be global). So it would be like this:

Code: Select all

Global OverWinID, AWinID
Return

#If (MouseIsOver("Chrome_WidgetWin_1"))						; If the mouse is hovering over a Chrome window AND it's not the active window, then  
^w::ControlSend, , ^w, ahk_id %OverWinID%
#If


MouseIsOver(WinTitle) {													; This function retrieves the active and inactive window IDs as well as the active window's class to use in the above #If statement
	MouseGetPos,,, OverWinID
	AWinID:=WinActive(A)
	WingetTitle, AWinTitle, A
	WinGetTitle, OverTitle, ahk_id %OverWinID%
	WinGetClass, OverWinClass, ahk_id %OverWinID%
	Return (WinTitle=OverWinClass) and (AWinTitle != OverWinTitle)
}
Return

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by boiler » 04 Feb 2020, 17:55

BannerStore wrote:
04 Feb 2020, 17:02
By the way, why is it important to make the condition written in the function rather than the If statement?
Even though it works the other way, it doesn’t make sense to have a function only do part of its job. You have it defining those variables for only that purpose, but then you don’t have the function actually do the comparison.

dinkleman
Posts: 3
Joined: 26 Nov 2022, 18:34

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by dinkleman » 26 Nov 2022, 18:36

Can someone post the full working code so i can just copy and paste it lol

antonio57
Posts: 4
Joined: 27 Apr 2022, 01:50

Re: Really Useful Script to Add to Your Collection!! (Send hotkeys to windows you are hovering over.)

Post by antonio57 » 21 Feb 2023, 14:58

People, you need use common sense to think about what code you write - not always a window can be identified by class.

This is not to mention the fact that your variable OverWinID received in the function is local and is not transferred outside - that is, it will not work... :crazy:

I would also recommend defining a function to send and using a shorter version of the notation - so you don't have to repeat the same thing over and over again ahk_id %OverWinID%. And you definetelly need doing sleep 500 after send to avoid double and more multiple triggering sending.)))

Code: Select all

#If mouseIsOver("ahk_class Chrome_WidgetWin_1")
^w::overWinControlSend("^w")
#If

; usage:
; "Google"
; "ahk_class Chrome_WidgetWin_1"
; "Google ahk_class Chrome_WidgetWin_1"
; "ahk_exe chrome.exe"
; ...
; Also of course don't forget about this :
; https://www.autohotkey.com/docs/v1/lib/SetTitleMatchMode.htm
mouseIsOver(search,mode=1) {
	global overWinID
	mouseGetPos,,,overWinID
	oldTitleMathMode:=A_TitleMatchMode
	setTitleMatchMode %mode%
	result:=winExist(search . " ahk_id " . overWinID)
	setTitleMatchMode %oldTitleMathMode%
	return (result) and (result != winExist("A"))
}

overWinControlSend(raw="",control="") {
	global overWinID
	controlSend,%control%,%raw%,ahk_id %overWinID%
	sleep 500
}

Post Reply

Return to “Ask for Help (v1)”