Categories
Uncategorized

Keyboard macro programming

Intro
I had the perfect motivation to learn a new tool. I had hundreds of repetitive keyboard clicks in my future. So my strong motivation was to save time.

The details

I needed to cancel about 300 changes in the Helpdesk system AHD (Advanced Helpdesk) from CA. First I turned to the team with the power tools and showed them what I needed. It looked readily doable. Move the mouse over here. Click. New Window pops up, in focus. Click on this drop-down menu item. Chance status to Cancel and Save. But for whatever reason they couldn’t do more than two, and then they lost their motivation.

Meanwhile my friend Nix told me about alternatives I could try on my own.

Workstation Macro Recorder from Automation Anywhere
First I tried this one. You only get a 30-day free trial. It was supposed to record my clicks and other keystrokes and then play them back. It didn’t work. Running it seemed to interfere with the browser window and the Javascript, which normally displays a menu during a mouse-over event was not behaving that way: no menu was popping up as long as this program was running.

AutoHotkey
So Nix suggested AutoHotkey. He warned it was a little buggy and cantankerous, but probably suitable for the task at hand.

There’s learning a language theoretically and learning a language to accomplish a very specific task. I’m not too good at the former, just doesn’t interest me and motivate me. But as I was saying I had great motivation for the latter. It wasn’t obvious at first how to proceed. But I started with a test script, which of course initially didn’t do anything at all. And then I slowly built up in complexity for the task at hand. It probably took several hours in total time spent over a few days.

The actual, working script, tested and used on my Windows 7 laptop, test.ahk

; launch by holding down Windows key, then pressing z key.
#z::
; loop five times
loop, 5 {
; Rt-arrow key
send {Right}
sleep, 100
; cancel out my AHD changes. u is for update
send u
sleep, 6000 ; 6 seconds
; now we need 3 tabs
loop, 3 {
send {tab}
sleep, 300
}
send Change is being cancelled.
;
loop, 6 {
sleep, 100
send {tab}
}
sleep 200
; c is for cancel
send c
; save it
send !s
sleep, 5000
; make next change the active one
send {tab}
sleep, 100
send {tab}
sleep, 100
}


Can you use AHD without mouse movement?

The problem I was solving is two-fold. AutoHotkey is not really great at mouse movement. So I needed to understand how to interact with AHD without using the mouse at all. It tuns out to be possible, at least mostly and sufficiently for my purposes. And I think it is important to mention because most users never get to this level: most programs do offer you a keyboard alternative to mouse movements and in fact it’s probably worth the time to find out what those are as it will almost always be faster than dragging that mouse pointer around to the precise locale of your next click.

I never did get the script to perfection, but that wasn’t the point. The point was to save my mind and my time. And it did work for that! There were always special conditions, etc which I did not code for and wasn’t motivated to code for. So I plowed through cancelling five changes at a time.

Conclusion
AutoHotkey proved to be quite helpful. Did I mention it is free? I recommend to use it to save on keystrokes for repetitive things.

References
Auto HotKey web site.

Leave a Reply

Your email address will not be published. Required fields are marked *