Author Topic: A simple AutoHotKey timesaver  (Read 484 times)

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2913
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
A simple AutoHotKey timesaver
« on: February 02, 2013, 11:54:21 am »
Hello all.

I'm in love with AutoHotKey (AHK) and it's such a big time saver that I cannot help but share this little piece of code for all of you!

You can download AHK here and for those of you who don't know what it is, click here

Synopsis of the purpose of AHK
Quote from: Wikipedia
AutoHotkey is a free, open-source macro-creation and automation software utility that allows users to automate repetitive tasks in Microsoft Windows. Any application user interface can be modified by AutoHotkey (for example, overriding the default Windows control key commands with their Emacs equivalents).[2] It is driven by a custom scripting language that is aimed specifically at providing keyboard shortcuts or hotkeys.


So, by now you can probably understand why it can save so much time. I even automated a game hack using AHK and veency on my old ipod (got banned, but I learned a lot lol)! It's VERY versatile.

So, I urge you to learn more about AHK beyond this simple code share (only sharing code, not going to explain it as it's pretty human readable and if you're interested, AHK is very well documented and I'm confident in the fact that everyone here can fully understand it and pick it up quickly, but if you do need help you can always PM me)

Here's the code:
Code: [Select]
RunProgram(wintitle, programlocation)
{
IfWinExist, %wintitle%
{
IfWinActive, %wintitle%
{
WinClose, %wintitle%
return
}
else
{
WinActivate, %wintitle%
return
}
}
else
{
Run %programlocation%
WinWait,%wintitle%,,10
If ErrorLevel
{
WinClose, A
}
WinActivate, %wintitle%
WinMaximize
return
}
}

How to use the code/what it does
That code is a function I wrote to automate the opening of a program.

If the program is not open, it opens it.
If the program is open but not active, it activates it
If the program is open and active, it closes it

Pretty simple, but you'd be surprised at how much time it saves!

To use it, make a new AHK script and type in something similar to this:
Code: [Select]
^!i::
{
RunProgram("iTunes", "C:\Program Files (x86)\iTunes\iTunes.exe")
return
}

This code runs the function when you press Control+Alt+I.
the "::" symbolize a hotkey, and a list can be found here.

Make sure you use the brackets and such as shown above, and include the return, or else you will not be able to string multiple hotkeys together.

To use the function, just pass 2 parameters to it, the first one being the window title and the second one being the path to the program you wish to run.
A quick note about the window title, include
Code: [Select]
SetTitleMatchMode, 2 somewhere in the script to make the window title only have to match part of the title (iTune will match iTunes, for instance, if you include that code. This is useful for chrome and different chrome windows, for example)


Any questions, leave a comment/PM me and I will help :)

Finally, I have many many other tricks, let me know if anyone is interested in saving more time!

Ironman

  • Administrator
  • Hero Member
  • *****
  • Posts: 5152
  • Reputation: 252
  • Badges:
  • Computers: ASUS UL50VT
  • iDevices: iPhone 5, iPhone 4S, iPhone 4, iPhone 3GS
Re: A simple AutoHotKey timesaver
« Reply #1 on: February 02, 2013, 01:05:58 pm »
This looks really cool!! Thanks for this. +1
Click for How to Add Our Repo
If you're going to ask questions....
At least make them good ones.

Knowledge is the one thing that can never be taken from you

grinch

  • Administrator
  • Hero Member
  • *****
  • Posts: 1942
  • Reputation: 188
  • dIGITAL gRINCH
    • @DigitalGrinch
  • Badges:
  • iDevices: iPhone 3GS 4.3.3, HTC Evo V 4G ICS
Re: A simple AutoHotKey timesaver
« Reply #2 on: February 02, 2013, 04:34:15 pm »
Really nice work on this

+1
If I help you or you appreciate my work, clicking that +1 button is the best thanks I could get.

My opinions are my own, you may agree or disagree with them, but they are only just that; opinions
For example: facebook is the microsoft of social networks

http://goo.gl/PiVjI

@DigitalGrinch
https://twitter.com/DigitalGrinch

I follow all iNinjas members back. PM me if I am not following you

edgarrivera

  • Noob
  • *
  • Posts: 36
  • Reputation: -6
    • ~~
Re: A simple AutoHotKey timesaver
« Reply #3 on: March 12, 2013, 09:00:00 am »
Been using AHK since a saw in a article few years back!  Its a most have tool.