1
votes

I've been using AHK in a very simple form for years, but multiple attempts at learning the more advanced functions has just resulted in confusion and frustration.

At the moment I'm trying to create a script that'll send the hotkey "CTRL + W" to Google Chrome when I hold the tilde key and left click inside the Google Chrome window. Whenever I trigger the script, it seems to close every single tab then the browser itself.

My script is below - what am I doing wrong?

#IfWinActive ahk_class Chrome_WidgetWin_1     ;Checks that the active window is Google Chrome.
` & LButton::                                 ;Tilde + Left Mouse Button
Send, ^+w                                     ;Sends CTRL + W to the window.
return                                        ;Ends the script.
1

1 Answers

1
votes

Your script looks almost right. Try this. After you defined all the keys, you must "close" #ifwinactive ...

#IfWinActive, ahk_class Chrome_WidgetWin_1
    ` & LButton::Send, ^+w
#IfWinActive  

Splitting the hotkey over multiple lines in not wrong, but in this case it can be done in one line. When you run into a problem like this. Try to isolate the issues. First ONLY try a bare ' & LButton::Send X to see if this works and be aware that you now loose the ` sign. Then try it with ^+w and when that works try it with #IfWinActive.

When you want to "restore" the tilde key, you could add this line:

~`::Return

The ~ will pass on the key data to the OS before executing the NOP (Return).