AutoHotkey Community

It is currently May 27th, 2012, 9:37 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Escape to Close
PostPosted: April 24th, 2006, 11:39 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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 September 5th, 2006, 10:49 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2006, 6:33 am 
Offline

Joined: April 25th, 2006, 12:33 pm
Posts: 15
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2006, 11:31 am 
Offline

Joined: February 17th, 2005, 10:06 am
Posts: 280
Location: Hungary, Budapest
2jballi
If you are interested, here is a more complicated approach, where you can decide if a program has to be closed or minimized on Esc:
http://www.ghisler.ch/wiki/index.php/Au ... ze_windows

_________________
Is there another word for synonym?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 29th, 2006, 5:51 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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.

SanskritFritz wrote:
... If you are interested, here is a more complicated approach, where you can decide if a program has to be closed or minimized on Esc:
http://www.ghisler.ch/wiki/index.php/Au ... ze_windows


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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Press Escape twice
PostPosted: May 11th, 2006, 10:40 am 
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....


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 11th, 2006, 11:15 am 
Offline

Joined: February 17th, 2005, 10:06 am
Posts: 280
Location: Hungary, Budapest
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2006, 3:32 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2006, 3:18 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2006, 6:39 am 
Offline

Joined: December 16th, 2005, 3:29 am
Posts: 148
Location: Australia
this is part of my admin.ahk script
Code:
esc::
Winclose, A
return

and yes, it is very important hotkey.

_________________
Image
546F206C69766520
6973204368726973742C0D746F2064696520
6973206761696E2E0D285068696C20313A323129


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Press Escape twice
PostPosted: June 3rd, 2006, 2:49 pm 
Offline

Joined: September 4th, 2004, 8:44 pm
Posts: 74
Location: UK
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Press Escape twice
PostPosted: June 3rd, 2006, 4:54 pm 
Offline

Joined: May 24th, 2006, 1:29 pm
Posts: 25
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

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2006, 5:53 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
Out of curiosity... was something wrong with using alt + F4 (if your keyboard has function keys...)? ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2006, 9:39 pm 
Offline

Joined: May 24th, 2006, 1:29 pm
Posts: 25
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

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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 5th, 2006, 11:19 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2006, 5:08 am 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
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..


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, nomissenrojb and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group