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 

Newby question - toggle, closing applications

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
New User
Guest





PostPosted: Tue Dec 12, 2006 1:18 am    Post subject: Newby question - toggle, closing applications Reply with quote

Hi Everyone,

I'm pretty new to AHK programme.

Any help with regards to my problems below would be most appreciated.

(1) I'm trying to create a simple toggle feature. So when I press "#n" notepad will open, if I press "#n" again it'll check to see if notepad is already opened. If so, then it'll close Notepad. Basically I'm trying to create a toggle feature for opening and closing notepad using the "#n".

;;This is what I've got so far.
;;Opens notepad but doesn't close it.
#n::
If WinExist("","Notepad")
WinClose, A
Else
Run Notepad

(2) Second question is kind of similar to the first. What is the syntax to close the currently active window (application). I mean is there a generic syntax that will close any application that is currently selected?

(3) To extend it even more. Is it possible to close all applications which are running the same process. For example, if I had eight IE browsers opened. Could I press a hotkey to close the current application and all other windows with the same application running on it? I'm pretty sure I'd need some kind of loop, and a property to check the class. But again I'm not too sure about the synatx.

Any help would be great.
Thanks in advance.
Back to top
.AHK



Joined: 26 Apr 2006
Posts: 662
Location: USA

PostPosted: Tue Dec 12, 2006 1:48 am    Post subject: Reply with quote

Code:

#n::
Process Exist, notepad.exe
If ErrorLevel <> 0
Process Close, notepad.exe
Else
Run notepad.exe
Return

Should work.
Back to top
View user's profile Send private message Visit poster's website AIM Address
New User
Guest





PostPosted: Tue Dec 12, 2006 2:13 am    Post subject: Reply with quote

Hi .AHK

The code works for (1). Thank you for the help.
Back to top
jps



Joined: 02 Sep 2006
Posts: 253
Location: Scotland

PostPosted: Tue Dec 12, 2006 4:30 am    Post subject: Reply with quote

(2)
Code:
!F4::WinClose, A


(3)
Code:

^!F4::
WinGetClass, ClassVar, A
GroupAdd, GroupVar , ahk_class %ClassVar%
GroupClose, GroupVar, A
return
Back to top
View user's profile Send private message
New User
Guest





PostPosted: Tue Dec 12, 2006 9:39 pm    Post subject: Reply with quote

Hi jps

Thank you for answering (2) and (3). They work great Very Happy
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help 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