Reputation: 148714
I want to simulate a "find" operation when I double click a word in Chrome.
I've managed to do this :
~LButton::
SetTitleMatchMode, 2
#IfWinActive, ahk_class Chrome
If (A_TimeSincePriorHotkey<400) and (A_TimeSincePriorHotkey<>-1)
{
SendInput ^c
Sleep, 10
SendInput ^f
Sleep, 10
SendInput ^v
}
Return
But it runs even for non-chrome process (when double click a word)
Question:
How can I make this script run only when double click in chrome ?
Upvotes: 2
Views: 3412
Reputation: 221
#IfWinActive, ahk_exe Chrome.exe ;; start of IfWinActive condition, for me it didn't work with ahk_class so i changed it to ahk_exe
~LButton::
SetTitleMatchMode, 2
If (A_TimeSincePriorHotkey<400) and (A_TimeSincePriorHotkey<>-1)
{
SendInput ^c
Sleep, 10
SendInput ^f
Sleep, 10
SendInput ^v
}
Return
~RButton::
SendInput {Escape}
Return
#IfWinActive ;; end of condition IfWinActive
Upvotes: 5
Reputation: 103
You can get the title of the window or active window with WinGet - and then only apply the code IF that given window is active.
SetTitleMatchMode, 2
This is a snippet I found:
DetectHiddenText, On ; the url of the active Chrome window is hidden text...
SetTitleMatchMode, Slow ; ...we also need match mode 'slow' to detect it
; activate chrome window,
; just for demonstation:
WinActivate, ahk_class Chrome_WidgetWin_1
IfWinActive, ahk_class Chrome_WidgetWin_1 ; we only want to check for the hidden text if Chrome is the active window,
{
WinGetText, wintext, ahk_class Chrome_WidgetWin_1 ; if it is we grab the text from the window...
If InStr(wintext,"autohotkey.com") ; ...and if it contains a url that we want,
{
;### code conditional on url goes here ###
msgbox % "The active Chrome window is on the autohotkey.com domain! The page title and URL is:`n`n>" wintext ; <<== we run the desired code here.
}
}
exitapp
but it needs to be changed to fit your specific needs.
Upvotes: 1