tags:

views:

62

answers:

2

I'm constantly activating Firefox then hitting Ctrl+L to activate the location bar and do a search or type a url.

Ideally I can be in any application and hit Ctrl+L and firefox will activated with the location bar activated and ready for input. In steps AutoHotkey scripting...

I've tried this and it doesn't seem to work. From what I've read, tilda is the "pass-through"

^l::
IfWinExist ahk_class MozillaUIWindowClass
{
    WinActivate
    Send ~^l
}

Thanks for the help.

A: 

I don't think the tilde applies in this instance, but Send might send the keys faster than the window actually activates, so something like this might be better:

SetKeyDelay, 10, 10 ; adds 10ms delay between and during keystrokes
IfWinExist, ahk_class MozillaUIWindowClass
{
   WinActivate,
   WinWaitActive, ; waits until window is active
   Send, ^l
}
return
sinkfaze
+1  A: 

Ended up getting the answer to this one myself on the AHK forum.
It requires the use of the dollar sign modifier ($).

$^l::
IfWinExist ahk_class MozillaUIWindowClass
{
    WinActivate
    Send ^l
}  


From AutoHotkey help:

($) This is usually only necessary if the script uses the Send command to send the keys that comprise the hotkey itself, which might otherwise cause it to trigger itself.


And here's the full script I ended up using. If Firefox is already active Ctrl+L is simply passed through and behaves as usual. If outside of Firefox when Ctrl+L is pressed then Firefox is activated and a new tab is created; ready for searching.

$^l::
IfWinExist ahk_class MozillaUIWindowClass
{
  IfWinActive ahk_class MozillaUIWindowClass
  {
    Send ^l
  }
  else
  {
    WinActivate
    Send ^t
  }
}
GollyJer