Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I used the WinClose Script in AutoHotKey to close windows with Ctrl+w (^w). As the Ctrl+w is sometimes already the shortcut to close a window (or tab in Firefox), I send again a Ctrl+w which ends then in a infinite loop I guess. How can I solve that?

This is the error message:

enter image description here

And this is my script:

;;; make the “CTRL+W” key to close window or tab.
; which key to send depends on the application
^w::
IfWinActive ahk_class ATH_Note
{ ; ATH_Note is Windows Mail
; Ctrl+F4
  Send !{F4}
}
IfWinActive ahk_class Notepad
{ ; Alt+F4
  Send !{F4}
}
Else IfWinActive ahk_class Outlook Express Browser Class
{ WinMinimize, A
}
Else IfWinActive ahk_class IrfanView
{ Send {Esc}
 }
Else ; IE, Firefox, Google Chrome, Opera
{  Send ^w
 }
Return
share|improve this question

2 Answers 2

up vote 6 down vote accepted

I would try using context-sensitive hotkeys instead of checking the active window on keypress. Your other hotkeys still work the same, but since your browsers are not specified, they will maintain their normal functionality. I created your desired functionality by using the code below:

#IfWinActive ahk_class ATH_Note
  ^w::Send !{F4}
#IfWinActive

#IfWinActive ahk_class Notepad
  ^w::Send !{F4}
#IfWinActive

#IfWinActive ahk_class Outlook Express Browser Class
  ^w::WinMinimize, A
#IfWinActive

#IfWinActive ahk_class IrfanView
  ^w::Esc
#IfWinActive

If there are some shared hotkeys between programs, you can also create groups:

GroupAdd, FileExplorer, ahk_class EVERYTHING
GroupAdd, FileExplorer, ahk_class CabinetWClass
GroupAdd, FileExplorer, ahk_class #32770

#IfWinActive ahk_group FileExplorer
    ^w::WinMinimize, A
#IfWinActive
share|improve this answer
    
Thanks good point, but the problem occurs with programs that I haven't in my script (the ELSE case). But you're right, maybe I should just do a context-sensitive script, only programs I'm aware of their hotkeys. –  FiveO Oct 19 '12 at 6:52

As I can see you don't have return in the if statement so that mean loop around until your script crash, also you have to put on else return, ... try this approach.

Edited:

    $^w::
IfWinActive ahk_class ATH_Note
{ ; ATH_Note is Windows Mail
; Ctrl+F4
  Send !{F4}
}
IfWinActive ahk_class Notepad
{ ; Alt+F4
  Send !{F4}
}
Else IfWinActive ahk_class Outlook Express Browser Class
{ WinMinimize, A
}
Else IfWinActive ahk_class IrfanView
{ Send {Esc}
 }  
else
{
Send ^{w}
return
}
Return

Use $ to prevent triggering many times when you use Send command. $

share|improve this answer
    
No, unfortunately if you send the ^w in the else statement (see my code), you will also end up in a loop (even with the return). –  FiveO Oct 19 '12 at 7:28
    
Code is edited and it's working, that will work without error and it will return when it's needed ... all the rest explanation is same –  tonni Oct 19 '12 at 12:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.