AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: close windows
PostPosted: October 6th, 2004, 12:50 pm 
Offline

Joined: September 4th, 2004, 8:44 pm
Posts: 74
Location: UK
my favourite definition. sends ^w or !f4, depending on which application is open.

and that ` key is nice and handy on the keyboard.

jack
you know where you are with a one-button mouse


Code:
`::
   SetTitleMatchMode 2
   WinGetActiveTitle thiswin

   if thiswin contains NetCaptor,Adobe FrameMaker,Mozilla
   {
      send ^w
      return
   }

   else IfWinActive Emacs ;not emacs, cos emacs uses this key
   {
      send {ASC 96} ; send self
      return
   }

   else IfWinActive Program Manager ; don't shut down windows
   {
      ; do nothing
   }

   else
   {
      send !{F4}
      return
   }

   return


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: close windows
PostPosted: November 14th, 2004, 1:19 am 
Great job covering your bases... But doesn't this work just as well?

Code:
`::
WinClose, A
return


This is more efficient since there's only three lines to process, and no keystrokes to send. It works for all self-contained windows. I don't have Emacs so I can't test it on that, but I'm reasonably sure it would still work. And, in the direction of efficiency, you can optimize it even further:

Code:
SetBatchLines, -1
SetWinDelay, -1
`::
WinClose, A
return


Of course, this still might not work for some windows, in which case your script would work better. I don't have any such applications to test it on. If this is the case, though, it still should be optimized. There is a gap, albeit an extremely small one, between key press and execution. Here's the optimized version (You can change the values to 0 rather than -1 if it causes an unwanted cpu spike):

Code:
SetBatchLines, -1
SetKeyDelay, -1

`::
   SetTitleMatchMode 2
   WinGetActiveTitle thiswin

   if thiswin contains NetCaptor,Adobe FrameMaker,Mozilla
   {
      send ^w
      return
   }

   else IfWinActive Emacs ;not emacs, cos emacs uses this key
   {
      send {ASC 96} ; send self
      return
   }

   else IfWinActive Program Manager ; don't shut down windows
   {
      ; do nothing
   }

   else
   {
      send !{F4}
      return
   }

   return


But if it works, the WinClose command would probably be better, not just for efficiency but because it's also more flexible.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2004, 9:29 am 
Offline

Joined: September 4th, 2004, 8:44 pm
Posts: 74
Location: UK
hello guest

you're quite right, of course -- winclose is better than !F4 and i expect it is quicker with the batchlines and windelay.

i've tried adding the new lines and unfortunately i can't see any difference. the windows used to close instantly before the improvements and they still do that after the improvements :)

i can't get rid of the emacs bit. i actually want the keystroke to go to emacs because i use it there for dynamic abbreviations (type some letters, press the key, it hunts back for a word beginning with those letters and completes the word).


thanks

jack
no matter how young a prune is, it's always full of wrinkles


Report this post
Top
 Profile  
Reply with quote  
 Post subject: close windows
PostPosted: November 14th, 2004, 10:02 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
Quote:
i've tried adding the new lines and unfortunately i can't see any difference. the windows used to close instantly before the improvements and they still do that after the improvements

Heh. You don't have to call those "improvements," the word I used was optimizing, meaning it speeds them up on a low level.

Anyway, I wasn't exactly talking about a noticeable difference in speed, but rather about the core efficiency of it. I'm a purist, so I try my best to only use hotkeys to execute functions when I need to, especially if another hotkey is activating the script. In this case, you could integrate the two, having WinClose in place of !F4, and having the hotkey for everything else.

As for my optimization, if the increase in speed is so subtle that it doesn't matter, you should probably remove them. It makes the script take full priority for as long as it takes to run, and while it's so small it usually won't matter, it's best not to have a tiny thing like this interrupting more important programs. Again, this is an extremely insignificant point, only to be taken if you're a perfectionist like me. :)

On the purist note, a non-sendkey alternative to the Emacs problem is this: Find the control using Winspector or Spy++ and use PostMessage to make the hotkey send that function to Emacs, instead of WinClose. See this thread for details on that. It's simpler than it sounds.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher, nomissenrojb, Stigg and 19 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