Autohotkey: Global Media Keys

Requirements

Installation

  1. copy/paste the code from the script below into a new file
  2. save that new file in a new folder (you can name it whatever you want)
  3. run the script
  4. done

Usage

  1. manually run the script once, it stays active unless you manually close it (if you use it frequently, you might want to consider adding it to your computers startup)
  2. done

Script

app_name = GlobalMediaKeys
app_ver = 0.01
app_author = Johan Klos

/*
Not every keyboard has media-keys. With this plugin you have default global media keys (CTRL-WIN-ALT up/left/right). 
If the script is Run as Admin (line 16: "runasadmin = 1") the hotkeys will work even if a program has focus that is running as admin.
If the script is not Run as Admin (line 16: "runasadmin = 0"), the hotkeys will not work when a program has focus that is running as admin.
*/

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

runasadmin = 0

if runasadmin = 1 
{
	full_command_line := DllCall("GetCommandLine", "str")

	if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
	{
		try
		{
			if A_IsCompiled
				Run *RunAs "%A_ScriptFullPath%" /restart
			else
				Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
		}
		ExitApp
	}
}

^#!UP::Media_Play_Pause
^#!RIGHT::Media_Next
^#!LEFT::Media_Prev

return

 

Autohotkey: updating portable software

Requirements

Installation

  1. copy/paste the code from the script below into a new file
  2. save that new file in a new folder (you can name it whatever you want)
  3. edit line 1 of the script to list the programs you want to use (by default: “ccleaner,speccy,defraggler,recuva”)
  4. run update_piriform.ahk (it will download unzip.exe if it doesn’t already exist in the same folder and start downloading/unzipping the files that are listed in the programs line)
  5. done

Usage

  1. manually run the script when you want to update the files listed on line 1
  2. done

Script

programs = ccleaner,speccy,defraggler,recuva

app_name = Piriform downloader
app_ver = 0.04
app_author = Johan Klos

/*
I use piriforms free tools to do some maintenance. 
Every so often I run this script to update the portable versions of those programs.
https://www.piriform.com/%program%/download/portable

it keeps the user informed using tooltips
*/

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force ; skips the dialog box and replaces the old instance automatically, which is similar in effect to the Reload command.

tooltip %app_name% v%app_ver%`nStarting program

; check if commandline unzip.exe program is present, if not, download it	
ifnotexist unzip.exe
{
	tooltip %app_name% v%app_ver%`nunzip.exe missing: downloading it now
	UrlDownloadToFile, http://www.kloscomputing.co.uk/public/unzip.exe, unzip.exe
}
	
loop, parse, programs, `,
{
	if ( A_LoopField <> "" )
	{
		download(A_LoopField)
	}
}
count = 3
loop, 3
{
	tooltip %app_name% v%app_ver%`nAll done: terminating program in %count% seconds.
	count--
	sleep 1000
}
exitapp

download(program)
{
	global app_name, app_ver
	
	; create an URL to download the program in question
	url := "https://www.piriform.com/" . program . "/download/portable/downloadfile"
	
	tooltip %app_name% v%app_ver%`n%program% downloading
	; download the zip file
	UrlDownloadToFile, %URL%, %A_Temp%\%program%.zip
	
	tooltip %app_name% v%app_ver%`n%program% unzipping
	runwait, unzip.exe -u "%A_Temp%\%program%.zip" -d "%A_ScriptDir%\%program%",, hide	

	tooltip %app_name% v%app_ver%`n%program% clean up files we won't need any more
	; do some cleanup work, remove the 
	FileDelete, %A_Temp%\%program%.zip
	return
}

 

 

Autohotkey: What is it?

From autohotkey.com:

AutoHotkey is a free, open-source scripting language for Windows that allows users to easily create small to complex scripts for all kinds of tasks such as: form fillers, auto-clicking, macros, etc.

Basically, it is a way to do a lot of different things a lot quicker.

Personally, I use it to make my life easier, for instance:

  • by updating portable software,
  • making hotkeys to do certain things such as media play/pause/next,
  • type passwords in games that don’t allow for pasting.

 

Each script is basically a tekst file with a .ahk extension. The .ahk file is then run (or executed) by Autohotkey.exe, which you can download from here

If you run into issues or have questions, the Autohotkey community is very active on forums and irc

A good editor that I use is Notepad ++

Loading