geekhack

geekhack Community => Keyboards => Topic started by: Herman on Tue, 15 May 2012, 14:41:09

Title: Autohotkey exit function
Post by: Herman on Tue, 15 May 2012, 14:41:09
Hi I just started using auto hot key, and i have some commands to open different things like this,

!^m::Run C:\music\mp3.m3u

!^d::Run C:\funny.vbs

this is just some examples, and as you can see my code is extremely simple.

my question is, I'm not the best at English, so I have some trouble to understand the different guides around the net, but i would like another shortcut so I can close these programs again, can somebody in here tell me how, or hand me a little piece of code I could steal.

Thanks in advance :)
Title: Autohotkey exit function
Post by: derek trousers on Wed, 16 May 2012, 17:08:54
Hey Herman. The fine guys at donationcoder.com might well be able to help you out. One guy, Skrommel, seems to be an AHK wizard...
Title: Autohotkey exit function
Post by: alaricljs on Wed, 16 May 2012, 17:12:12
Here's one that'll pop the calculator app:

Code: [Select]
#c::  ; Calculator
  IfWinExist Calculator
    IfWinActive Calculator
      WinClose
    else
      WinActivate
  else
    Run C:\Windows\system32\calc.exe
return

If the Calculator has focus, it'll close it.  If it's running but doesn't have focus it'll pull it to the front and focus it.  If it's not running, it'll run it.

To change it to open and close Calculator regardless of focus:
Code: [Select]
#c::  ; Calculator
  IfWinExist Calculator
      WinClose
  else
    Run C:\Windows\system32\calc.exe
return
Title: Autohotkey exit function
Post by: laffindude on Thu, 17 May 2012, 10:38:29
^I like the calc toggle. Thanks ;D
Title: Autohotkey exit function
Post by: alaricljs on Thu, 17 May 2012, 10:43:55
Oh hey, be warned, I haven't rewritten this one because it rarely blows up. The word Calculator in a browser window will cause that window to be closed instead of calc opening... :sorry:

ok, that was easy:

Code: [Select]
#c::  ; Calculator
Launch_App2::
  IfWinExist ahk_class CalcFrame
    IfWinActive ahk_class CalcFrame
      WinClose
    else
      WinActivate
  else
    Run C:\Windows\system32\calc.exe
return
Title: Autohotkey exit function
Post by: laffindude on Thu, 17 May 2012, 10:53:03
Well, you can always use:
Code: [Select]

#c::  ; Calculator
  IfWinExist Calculator
      Process, close, calc.exe
  else
    Run C:\Windows\system32\calc.exe
return
Title: Autohotkey exit function
Post by: alaricljs on Thu, 17 May 2012, 11:04:02
That would work for the case where the Calculator is running but you also have a browser up w/ Calculator.  But if calc wasn't running and the browser was, nothing would happen.  So I modified it to the Window Class instead of title matching.
Title: Autohotkey exit function
Post by: laffindude on Thu, 17 May 2012, 11:18:11
True. I guess I could try to detect the calc.exe process. Lemme see if I can get it done with less code
Code: [Select]

Process, exist, calc.exe
If ErrorLevel
      Process, close, calc.exe
  else
    Run C:\Windows\system32\calc.exe
return