 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
jballi
Joined: 01 Oct 2005 Posts: 385 Location: Texas, USA
|
Posted: Mon Apr 24, 2006 10:39 pm Post subject: Escape to Close |
|
|
Everyone has one or more short-timer programs. You know the type. You open the program (usually a utility), you get it to do stuff (1 or 2 minutes at the most), and then to get it out of the way, you close it.
Many releases ago, IrfanView included a simple but effective option for closing the application quickly: the Escape key. For many IrfanView users like myself, the Escape key is a perfect way to quickly close the application. I primarily use the program to view 1 or 2 images and then hit the Escape key to get it out way.
Anywho, I use a couple of drag-and-drop utilities that can only be closed with context menu or with a key-combination. As I was grumbling as to how much a pain-in-the-butt is was to close these boogers, I thought, "Why not close these with the Escape key just like IrfanView?" Then as I was coding for those guys, I thought, "Hey! There are probably a bunch of other programs that can be closed this way!"
There are 2 steps to the process. The first step is to define the group. Here's an example:
| Code: | GroupAdd $EscapeGroup,ahk_class lamedropXPd
GroupAdd $EscapeGroup,MP3Gain
GroupAdd $EscapeGroup,ahk_class oggdropWin
GroupAdd $EscapeGroup,QuickPar -
|
When you discover a new program that can/should be Escape closed, just add it to the group.
For my personal use I'm thinking about putting the windows in this group into a configuration file so that I can add/delete windows/classes to/from the group without changing the AHK code. I'm still not sure whether it merits the trouble.
The second step is to define the hotkey. Here's an example:
| Code: | #IfWinActive ahk_group $EscapeGroup
Escape::
#IfWinActive
;-- Close window
WinClose
;-- Return to sender
return
|
IMHO, not applications are good candidates for a quick close. Any program where you could possibly lose work, settings, or time probably shouldn't be closed without additional thought or action.
This is certainly not a new or original idea but the recently introduced #IfWinActive directive has made this task much easier to code for. Thank you Chris! I've included this code just in case you think it's a good idea too.
Last edited by jballi on Tue Sep 05, 2006 9:49 am; edited 1 time in total |
|
| Back to top |
|
 |
baby-luck
Joined: 25 Apr 2006 Posts: 15
|
Posted: Fri Apr 28, 2006 5:33 am Post subject: |
|
|
hi,
have you been running this for a while now? how is it working out?
i am wondering because i have just finished a gesture script for Windows Explorer with various functions (using the same gesture definitions as Opera, which if daily use for a couple of day goes well, I'll put up here also)
it has also been obvious that several of the gestures could apply other programs, exactly as you mention and with the same considerations.
so, yeh, has it been useful for you? |
|
| Back to top |
|
 |
SanskritFritz
Joined: 17 Feb 2005 Posts: 283 Location: Hungary, Budapest
|
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 385 Location: Texas, USA
|
Posted: Sat Apr 29, 2006 4:51 am Post subject: |
|
|
| baby-luck wrote: | ... have you been running this for a while now? how is it working out?
|
I have been very pleased with the results. I love getting these programs out of the way with a single key stroke. I recently added "7-Zip File Manager" to my list of programs to close with Escape.
As I hinted to in my original post, I did end up moving the "Escape to Close" program list to a configuration file. This allows the program list to be modified without modifying the script and if desired, it allow the feature to produce different results on different computers.
This is the exact same idea but with a lot more options. The Escape to Minimize is a good idea. I might adapt it for a couple of programs that I use so that I can get the program out of the way without closing it. Thanks for sharing!
Them be my thoughts... |
|
| Back to top |
|
 |
emisjerry Guest
|
Posted: Thu May 11, 2006 9:40 am Post subject: Press Escape twice |
|
|
Since the normal Escape has its own functionality, could I press Escape twice to close the window. Using this method, i can ignore the group or file to identify which need to be closed.
Is there any way to press a key twice? ~Esc & Esc:: cannot work.... |
|
| Back to top |
|
 |
SanskritFritz
Joined: 17 Feb 2005 Posts: 283 Location: Hungary, Budapest
|
Posted: Thu May 11, 2006 10:15 am Post subject: |
|
|
You have to set up a timer on the first Esc. Then if the second Esc is within the allotted time, you take appropriate action. See an example for this technique in the EasyWindowDrag_(KDE) script, where there is a double Alt keypress handled. _________________ Is there another word for synonym? |
|
| Back to top |
|
 |
emisjerry Guest
|
Posted: Sun May 14, 2006 2:32 pm Post subject: |
|
|
It seems cannor work. Here is what i've tried:
(Pess Ctrl twice)
| Code: | ~Ctrl::
Keywait, Ctrl, , t0.3
if errorlevel = 1
return
else
Keywait, Ctrl, d, t0.1
if errorlevel = 0
{
;MsgBox Closing!
WinGetActiveTitle, Title
WinClose, %Title%
return
}
return |
|
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 385 Location: Texas, USA
|
Posted: Mon May 15, 2006 2:18 am Post subject: |
|
|
| emisjerry wrote: | | It seems cannor work. Here is what i've tried ... |
Here is a double escape example using a couple of global variables to compute/track the amount time that has elapsed since the Escape key was pressed last:
| Code: | #IfWinActive ahk_class SciCalc
~Escape::
#IfWinActive
;-- 1st run?
if strlen(CalculatorTickCount)=0
CalculatorElapsedTime=99999
else
CalculatorElapsedTime:=A_TickCount-CalculatorTickCount
;-- Double Escape?
if CalculatorElapsedTime<300
WinClose
;-- Set CalculatorTickCount
CalculatorTickCount:=A_TickCount
;-- Return to sender
return
|
The Calculator program is good example because entering a single Escape key has a functional value -- it is the equivalent of hitting the Clear button.
Of course, there are are many ways to resolve this problem. This is just one of them.
Them be my thoughts... |
|
| Back to top |
|
 |
ParanoidX
Joined: 16 Dec 2005 Posts: 149 Location: Australia
|
Posted: Thu Jun 01, 2006 5:39 am Post subject: |
|
|
this is part of my admin.ahk script
| Code: |
esc::
Winclose, A
return
|
and yes, it is very important hotkey. _________________
546F206C69766520
6973204368726973742C0D746F2064696520
6973206761696E2E0D285068696C20313A323129 |
|
| Back to top |
|
 |
jack
Joined: 04 Sep 2004 Posts: 77 Location: UK
|
Posted: Sat Jun 03, 2006 1:49 pm Post subject: Re: Press Escape twice |
|
|
| emisjerry wrote: | Since the normal Escape has its own functionality, could I press Escape twice to close the window. Using this method, i can ignore the group or file to identify which need to be closed.
Is there any way to press a key twice? ~Esc & Esc:: cannot work.... |
i dunno about pressing ESC twice, but i also do a one-key close that i have coded on the ` key, which for me is the one just below ESC. that way i never interefere with ESC.
jack
insanely complex and egregiously stateful |
|
| Back to top |
|
 |
Moderator!
Joined: 24 May 2006 Posts: 25
|
Posted: Sat Jun 03, 2006 3:54 pm Post subject: Re: Press Escape twice |
|
|
| emisjerry wrote: | Since the normal Escape has its own functionality, could I press Escape twice to close the window. Using this method, i can ignore the group or file to identify which need to be closed.
Is there any way to press a key twice? ~Esc & Esc:: cannot work.... |
the following code detects double-press of esc within a duration of 200ms and closes the active window
adjust
If (A_TickCount-TC) > 200
to suit needs
| Code: | ~Escape::
Loop, {
EscDown:=GetKeyState("Escape","P")
If (!EscDown)
Break
}
TC := A_TickCount
Loop, {
EscDown:=GetKeyState("Escape","P")
If EscDown {
PostMessage, 0x112, 0xF060,,, A
Break
}
If (A_TickCount-TC) > 200
Break
}
Return |
_________________
 |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2436
|
Posted: Sat Jun 03, 2006 4:53 pm Post subject: |
|
|
Out of curiosity... was something wrong with using alt + F4 (if your keyboard has function keys...)?  |
|
| Back to top |
|
 |
Moderator!
Joined: 24 May 2006 Posts: 25
|
Posted: Sat Jun 03, 2006 8:39 pm Post subject: |
|
|
| corrupt wrote: | Out of curiosity... was something wrong with using alt + F4 (if your keyboard has function keys...)?  |
nothing wrong with alt+f4
i prefer postmessage over send
| http://www.autohotkey.com/docs/commands/WinClose.htm wrote: | WinClose sends a WM_CLOSE message to the target window, which is a somewhat forceful method of closing it. An alternate method of closing is to send the following message. It might produce different behavior because it is similar in effect to pressing Alt-F4 or clicking the window's close button in its title bar:
PostMessage, 0x112, 0xF060,,, WinTitle, WinText ; 0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE
If a window does not close via WinClose, you can force it to close with WinKill. |
_________________
 |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 385 Location: Texas, USA
|
Posted: Tue Sep 05, 2006 10:19 am Post subject: |
|
|
It's taken me a while, but I've changed my position on using SendMessage 0x112,0xF060 to close a window, at least for this mini-app when the list of applications/windows to be Escape-closed may change from day to day. It has become my opinion that the SendMessage 0x112,0xF060 command many times asks too politely to close the window/application. When asked, a defiant application may respond (if it could talk), "Well, if you're going to ask politely, then NO!".
When a application/window is added to the $EscapeToClose group, closing the application/window using the Escape key becomes stuck in the psyche. If an application doesn't close when you hit the Escape key, you keep hitting the Escape key until it closes or until you give up. If you're still frustrated, a short detour to the garage to find a hammer might be a short-term solution...
The good 'ole WinClose command is probably more appropriate for this mini-app. It is a lot more forceful than the SendMessage 0x112,0xF060 statement and under most circumstances, it's the equivalent of clicking on the Close button on the title bar.
I've updated the 1st post to reflect this micro-change in philosophy. Your comments and opinions are welcome. |
|
| Back to top |
|
 |
badmojo
Joined: 11 Nov 2005 Posts: 150
|
Posted: Mon Nov 13, 2006 4:08 am Post subject: |
|
|
jballi:
i've been trying to construct a script akin to yours here.
but since i realize that you had started earlier than me, i was wondering you have a working script available that can be used in daily environment. especially, when dealing with apps that use Escape intrinsically. i'm still tinkering but the results are not that good.. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|