Author Topic: Autohotkey exit function  (Read 2122 times)

0 Members and 1 Guest are viewing this topic.

Herman

  •  Guest
Autohotkey exit function
« 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 :)

Offline derek trousers

  • Posts: 45
Autohotkey exit function
« Reply #1 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...

Offline alaricljs

  • I be WOT'ing all day...
  • ** Moderator Emeritus
  • Posts: 3715
  • Location: NE US
Autohotkey exit function
« Reply #2 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
Filco w/ Imsto thick PBT
Ducky 1087XM PCB+Plate, w/ Matias "Quiet Click" spring-swapped w/ XM Greens

Offline laffindude

  • Posts: 1521
  • ( ̽ ¬ ˳¬)
Autohotkey exit function
« Reply #3 on: Thu, 17 May 2012, 10:38:29 »
^I like the calc toggle. Thanks ;D

Offline alaricljs

  • I be WOT'ing all day...
  • ** Moderator Emeritus
  • Posts: 3715
  • Location: NE US
Autohotkey exit function
« Reply #4 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
« Last Edit: Thu, 17 May 2012, 10:46:24 by alaricljs »
Filco w/ Imsto thick PBT
Ducky 1087XM PCB+Plate, w/ Matias "Quiet Click" spring-swapped w/ XM Greens

Offline laffindude

  • Posts: 1521
  • ( ̽ ¬ ˳¬)
Autohotkey exit function
« Reply #5 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

Offline alaricljs

  • I be WOT'ing all day...
  • ** Moderator Emeritus
  • Posts: 3715
  • Location: NE US
Autohotkey exit function
« Reply #6 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.
Filco w/ Imsto thick PBT
Ducky 1087XM PCB+Plate, w/ Matias "Quiet Click" spring-swapped w/ XM Greens

Offline laffindude

  • Posts: 1521
  • ( ̽ ¬ ˳¬)
Autohotkey exit function
« Reply #7 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