AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

close windows

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
jack



Joined: 04 Sep 2004
Posts: 74
Location: UK

PostPosted: Wed Oct 06, 2004 12:50 pm    Post subject: close windows Reply with quote

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
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Nov 14, 2004 1:19 am    Post subject: Re: close windows Reply with quote

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.
Back to top
jack



Joined: 04 Sep 2004
Posts: 74
Location: UK

PostPosted: Sun Nov 14, 2004 9:29 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3005
Location: Minnesota

PostPosted: Sun Nov 14, 2004 10:02 pm    Post subject: close windows Reply with quote

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

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group