Using AutoHotkey in PLC Programming

Using AutoHotkey in PLC Programming

Oftentimes, we must perform monotonous, repetitive tasks—and just about every time, it’s mind-numbingly boring. Thankfully, though, we can make our lives saner through automation!

AutoHotkey is a simple scripting tool that allows you to program custom keystrokes and commands. Though simple in design, it’s a very powerful tool; it’s able to perform tasks such as launching apps, making mouse movements, scheduling tasks, and so much more. AutoHotkey has some great documentation for writing scripts, so I’ll cover the applications I’ve found to be the most useful and some relevant examples.

Comment Tag

The script that I use most often is a comment tag. This script grabs the current time and date, types them out in a clean format, and adds “DMC:[my initials].” Now, you can track changes at the click of a button. For my example, It would end up looking like this:   -12/06/2019-DMC:JAK-

FormatTime, Time,, MM/DD/YYYY h:mm
SendInput -%A_MM%/%A_DD%/%A_YYYY%-DMC:JAK-

Multi-Device Monitoring

 An example of when I used this script was when adding device blocks in PLC programming.  In my use case, we had hundreds of devices. We wanted to link the output of the block to its instance memory, so we could monitor the status of these outputs. Therefore, I made a script that would paste what was in my clipboard (the base struct), append each output, and finally link it to each output of that device.  It took me only about 90 seconds to write the script and saved me a ton of blood, sweat, and tears.

;Simocode Motor.
Send, ^v
Send, .bOutForward {Enter}
Send, ^v
Send, .bOutAuto {Enter}
Send, ^v
Send, .bOutAlarm {Enter}
Send, ^v
Send, .bOutPLCControl {Enter}
Send, ^v
Send, .rOutCurrent {Enter}
Send, ^v
Send, .rOutCurrent_L1 {Enter}
Send, ^v
Send, .rOutCurrent_L2 {Enter}
Send, ^v
Send, .rOutCurrent_L3 {Enter}
Send, ^v
Send, .wOutStatusWord {Enter}
Send, ^v
Send, .bOutInterlocksOK {Enter}



Another great use case is when there are tools or functions that don't have hotkeys. A project I was working on had a button that changed the view of the window but had no keyboard shortcut back to the main view. Since we can script mouse movements, I was able to navigate to the button and simulate a click—returning to the main view.

;main view in GRAPH
Send ^1
MouseMove, 71, 148, 0
Send ^1

If you are using mouse movements, you can use the WindowSpy.ahk script in the installation folder to figure out where you need to move the mouse!


Changing Tags While in Run Mode

Another time I used this script was on a Rockwell project. There were many of us working off the same PLC, so it had to be in run mode. This made it impossible to do a “Find and Replace” function since each rung must be put into edit mode before any changes can be made. This made my job of updating hundreds of old tag references and add g_ to the beginning (pointing to the new tag) a lot more difficult.  Since I couldn't use the “Replace” function, I made an AutoHotkey script to help me out. To use this script, I used the “Find” feature and once the relevant tag is found, I ran the script to edit the rung and change the tag. I didn’t even have to move the mouse off the next button!

SendInput {Control Down}{Shift Down}{s Down}{Control Up}{Shift Up}{s up}
send {Enter}
Send {Home}
Send g
Send _

As you can see, AutoHotkey is an incredibly versatile, essential tool for speeding up workflows and creating additional functionality to your automation tools.

Learn more about DMC's expertise in PLC programming and contact us today to get started on your next project. 


There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

Enter the code shown above:

Related Blog Posts