4

In Autohotkey, how can I make NumpadDot double-click if Foxit Reader is active, otherwise send a normal NumpadDot?

My (broken) attempt:

NumpadDot::
  SetTitleMatchMode 2 ; allow partial titles
  IfWinActive, Foxit
      Click 2
  else
      Send {NumpadDot} ; THIS CREATES AN ENDLESS LOOP!
Return
mellow-yellow
  • 1,670
  • 1
  • 18
  • 38

4 Answers4

4

I recommend @RobertIlbrink's answer, but here's another way to do it.

$NumpadDot::
IfWinActive, Foxit
    Click 2
else
    SendInput {NumpadDot}
return

The $ prevents AutoHotkey from confusing sent keystrokes (via Send commands) with keypresses made by the user. If we didn't put that, we would get an infinite loop.

Brigand
  • 84,529
  • 20
  • 165
  • 173
2

Well, I would do it this way:

SetTitleMatchMode 2 ; allow partial titles

#IfWinActive, Foxit ; Any hotkeys defined between #IfWInActive ONLY works in Foxit
  NumpadDot::Click 2
#IfWinActive

Oh btw the endless loop is because your Send, {NumPadDot} initiates your own script. If you want to prevent that place a $ before the hotkey like this $NumpadDot::

Brigand
  • 84,529
  • 20
  • 165
  • 173
Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32
  • Works perfectly. Thanks! I had avoided this approach, perhaps wrongly, because of performance reasons: each key pressed must evaluate if Foxit is active, as opposed to first evaluating which key was pressed. – mellow-yellow Apr 05 '13 at 18:29
  • I made a small edit to clarify that only hotkeys are affected by `#IfWinActive`. Other code will still run, with no effect. – Brigand Apr 06 '13 at 13:49
1

I Have solved it through "SendPlay", in this example i have 2 keyboards, so i use {tab} from keyboard1 to do {RAlt}{TAb} to Windows and I use {tab} from the main keyboard to do the usual stuff

Tab::
  getKeyboardID()               ; AHKHID based routine
  if(kbID = keyboard1){
    send, {Ralt Down}{Tab}{RAlt Up}
  } Else {
   SendPlay {Tab}               ; here the solution
  }
Return
GCoro
  • 71
  • 1
  • 2
0

You don't have to have the else statement:

 NumpadDot::
     SetTitleMatchMode 2 ; allow partial titles
     IfWinActive, Foxit
 Click 2

return 
Robert
  • 4,306
  • 11
  • 45
  • 95
  • when I copy and paste this to Autohotkey and reload the script, then go to Notepad and press the period on the numeric keypad, no period appears. How can I make the period appear? – mellow-yellow Apr 05 '13 at 18:19