Archive for the ‘AutoHotKey’ Category


Presentations – Keeping your screen active


Power saving options on computers are something that I personally think are great.  They not only help reduce carbon footprints, but they also help draw out even more life from your laptop battery.   One of the main ways in which this is done (others being things such as disabling hardware) is by having an inactivity option that turns off the screen and the hard disk after a period of inactivity.  Unfortunately there are times when this isn’t something you want.  The primary example of this is when you are giving a presentation.

The typical way of overriding this in Windows is to change what power saving scheme is being used through the Windows control panel or a third party application that links directly to these options.  However sometimes end users don’t have access to this.

This typically occurs where a group policy has been applied to stop users ‘tinkering’ with the power saving schemes.  Users with access can amend or delete power saving schemes which can lead to complications with machines and so it is not that uncommon to restrict access.

Whilst applications such as Microsoft PowerPoint can lead the OS into knowing that it should keep things like monitors on if a presentation is in a browser or some other “power unaware” application, then power saving actions can kick in.

I decided to apply a brute force solution to this by creating an AutoHotKey script to send a key press to the OS at regular intervals.  By default it sends a Shift key press as this is least likely to have any impact on any application, but this can be modified along with the frequency with which it is sent by the use of a settings file.  The settings file also includes an option to choose whether to start sending key presses as soon as it is run.

The code for the script is given at the end of this post, but I have also compiled this into a stand alone executable that you could even pop onto your flash drive if you’re going to be presenting on someone else’s PC.  Similarly you could add it into your start-up group (with it set not to auto start sending key presses) so it is always there when you need it.

The script places a monitor icon in the system tray.  When it is black power saving actions through inactivity will take place.  When it is blue, key presses will be sent.  Right clicking on the icon will display a menu with an override option.  Selecting this option will place a check mark next to it which will set the icon blue and initiate the override mode.  Selecting the option again will uncheck it, set the icon black and turn off the override mode.

Only one setting is available on the settings menu.  This is another check item and determines whether override mode should be enabled immediately when the utility is first started.

The utility looks for a settings file called ActiveDisplay.ini in the folder from which the utility is being run.  If it does not exist, the utility will use its default settings which match the settings given in this example file:

;Set to 1 to enable override mode at start-up and 0 to disable.
;Specify what characters should be sent.  Use {} for special key strokes
;Number of milliseconds between sending the key strokes (120,000 milliseconds : 2 minutes)

If you want to tweak the script to meet your own needs you can get the details below and use your own icons.  If you want to get the compiled version you can download it for free.


;Read in settings
iniread, EnableAtStartup, %A_ScriptDir%\ActiveDisplay.ini, Settings, EnableOnRun, 0
iniread, KeyStroke, %A_ScriptDir%\ActiveDisplay.ini, Settings, KeyStroke, {Shift}
iniread, Period, %A_ScriptDir%\ActiveDisplay.ini, Settings, Period, 120000

;Create the tray menu
menu, tray, add, Override, Override
Menu, SettingsMenu, add, EnabledAtStartup
Menu, tray, add, Settings, :SettingsMenu
menu, tray, add, About
menu, tray, add, Exit
menu, tray, nostandard

;Time to do something that seems crazy - we'll flip these and then call the menu selection routines where it will get flipped back
EnableTimer := EnableAtStartup
EnableAtStartup := Not(EnableAtStartup)
GoSub, EnabledAtStartup
EnableTimer := Not(EnableTimer)
GoSub, Override


Send %KeyStroke%

EnableTimer := Not(EnableTimer)
If EnableTimer
 menu, tray, Check, Override
 menu, tray, icon, C:\Icons\Monitor On.ico
 menu, tray, tip, Default Power Saving Mode Overridden
 SetTimer, SendKeyStroke, %Period%
 menu, tray, UnCheck, Override
 menu, tray, icon, C:\Icons\Monitor Off.ico
 menu, tray, tip, Default Power Saving Mode
 SetTimer, SendKeyStroke, Off

EnableAtStartup := Not(EnableAtStartup)
If EnableAtStartup
 menu, SettingsMenu, Check, EnabledAtStartup
 iniwrite, 1, %A_ScriptDir%\ActiveDisplay.ini, Settings, EnableOnRun
 menu, SettingsMenu, UnCheck, EnabledAtStartup
 iniwrite, 0, %A_ScriptDir%\ActiveDisplay.ini, Settings, EnableOnRun

MsgBox, 0, About Active Display, Version 1.0`nCopyright 2009 RebootIT`n`n


AutoHotKey – Portable Drive Menu


I’m a big fan of portable applications and particularly the work driven by  The PortableApps Menu has been undergoing a revamp for some time now to work towards a number of enhancements and in the mean time I’ve taken up using a branch of this known as Geek Menu.  Unfortunately they are all quite slow as I have a huge number of portable applications on my portable hard drive.

I usually have a small number of applications I use regularly and so I actually want a fast loading light menu for automatic loading and then I load Geek Menu from that should I need access to lots of applications or ones that I use infrequently.

I’ve created a basic little application menu using AutoHotKey that is driven from a simple INI file menu system (that you manually edit) to fill this need.  When run it sits in the system tray and when you click on it it displays a set of menu items (including sub menus) and executes the item associated with it using the path for it in the INI file.

The script for this is as follows:

; Copyright 2009


AppName = PUMAS
AppIni = %A_ScriptDir%pumas.ini
IconFile = %A_ScriptDir%pumas.ico

;Build Menu;
;Set-up Base Menu Settings
menu, tray, Icon, %IconFile%
menu, tray, tip, %AppName%
menu, tray, nostandard
menu, tray, add, %AppName%, Heading
menu, tray, Default, %AppName%
menu, tray, disable, %AppName%
menu, tray, click, 1
menu, tray, add ; separator

;Build the base menu
BuildMenu("Tray", AppIni)

;Exit app entry
menu, tray, add ; separator
menu, tray, add, Exit, ExitApplication


;Recursive function to build the menu
BuildMenu(MenuSection, INIFile)
    ;Build menus from INI file
        IniRead, MenuEntry, %INIFile%, %MenuSection%, Item%Counter%, *
        If (MenuEntry="*")
        IniRead, MenuEntryPath, %INIFile%, %MenuSection%, %MenuEntry%, *
        If (MenuEntryPath="*")
            BuildMenu(MenuEntry, INIFile)
            menu, %MenuSection%, add, %MenuEntry%, :%MenuEntry%
            menu, %MenuSection%, add, %MenuEntry%, ExecuteItem
        Counter += 1


;The heading is disabled and simply allows the left click to produce
;the right click context menu
menu, tray, show

;Open the specified path for the menu item generated from the INI file
;Open the item specified for this in the ini file
IniRead, MenuEntryPath, %AppIni%, %A_ThisMenu%, %A_ThisMenuItem%
SplitPath, A_ScriptDir, , , , , ScriptDrive
Run, %ScriptDrive%%MenuEntryPath%

;Close the application

There are a few variables in the initialise section that specify the name of the application, the INI file that defines the menu (which is convenient to store in the same folder as the menu script/executable and the icon file for the application.

The INI file has a “Tray” section which defines the root content of the tray item’s context menu.  Each item is specified by “Item#” in numeric order.  Each item specified will either have an entry in the same section (making it an item for execution) or a section of the same name (indicating it is a sub-menu).

An example menu might look something like:



Item2=Format Floppy

Defrag=File HelpersUnfrag.exe
Format Floppy=batchformatFD.bat

Item1=Tools Guide
Item2=Mega Kit

Tools Guide=ToolsGuide.doc
Mega Kit=Toolsmegakit.exe

This produces a menu system with two sub menus (one for utilities and one for tools) each with two items and a help item on the root menu.  This configuration file specifies all paths in relation to the root of the drive it is stored on.  You can tailor this INI file to your needs and even the menu system itself by modifying the script to what you want – just recompile it with the AutoHotKey compilation tool and you’ve got it.