CoolTerm Marcos using AutoHotKey

If you have specific questions or problems with any of my Freeware applications, post them here.
Post Reply
User avatar
roger
Site Admin
Posts: 431
Joined: Fri Apr 24, 2009 12:41 am
Contact:

CoolTerm Marcos using AutoHotKey

Post by roger »

While CoolTerm doesn't currently support automation on platforms other than the Mac (using AppleScript), Windows users have a very handy and free automation environment at their disposal with https://www.autohotkey.com/.

An often requested feature for CoolTerm is the addition of transmit marcros allowing the user to send predefined strings of text via the click of a button or the press of a key on the keyboard. AutoHotKey supports this functionality very nicely, and its scripting language is very easy to learn. Here are a few examples of how CoolTerm can be automated with AutoHotKey:

Keyboard Macros:
The simplest way to send predefined text with CoolTerm is to use AutoHotKey to re-map certain keys on the keyboard. Here is an example:

Code: Select all

#IfWinActive, ahk_exe CoolTerm.exe

1::Send Macro Text 1
2::Send Macro Text 2
3::Send Macro Text 3

0::ExitApp
The script above repurposes the numeric keys 1 through 3 to send a certain text sequence. For example, when the "1" key is pressed on the keyboard, this script will send the keystrokes for "Macro Text 1" instead. The line #IfWinActive, ahk_exe CoolTerm.exe ensures that remapping only occurs when CoolTerm is the active application. In addition to mapping numeric keys 1 through 3, the script also remaps key 0 to terminate the script to provide an easy way to stop the script if needed.

GUI Macro Buttons:
For those who prefer a window with buttons to trigger certain transmit macros, AutoHotKey offers a solution as well:

Code: Select all

Gui, New, +AlwaysOnTop, CoolTerm Macros
Gui, Add, Button, gM1, Macro Button 1
Gui, Add, Button, gM2, Macro Button 2
Gui, Add, Button, gM3, Macro Button 3
Gui, Show
return

M1:
WinActivate, ahk_exe CoolTerm.exe
	send Macro Text 1
return

M2:
WinActivate, ahk_exe CoolTerm.exe
	send Macro Text 2
return

M3:
WinActivate, ahk_exe CoolTerm.exe
	send Macro Text 2
return

GuiClose:
ExitApp
The script above creates a window with 3 push buttons, each of which tied to a different macro. Pressing any of the 3 buttons will first bring CoolTerm to the forground and then send the specified macro text. Closing the window with the buttons will terminate the script.
AHK_GUI.png
For more information on how to use AutoHotKey, refer to the documentation here: https://www.autohotkey.com/docs/AutoHotkey.htm
You do not have the required permissions to view the files attached to this post.
jmuhammad
Posts: 14
Joined: Wed Aug 17, 2022 10:21 pm

Re: CoolTerm Marcos using AutoHotKey

Post by jmuhammad »

Thanks Roger!
I used this and updated it for my usage.

Image
Sharing generic code:
-One button edits THIS ahk script (update with full path of editor and ahk script)
-One button toggles CoolTerm "Always on Top"
-Spare 'header' button

-Six configurable buttons.
-J.Muhammad

Code: Select all

;  Program Name: CoolTermMacros.ahk
;        Author: J.Muhammad
;          Date: 20220818-1239
;------------------------------------------------------------------------------
;   Revision(s): 1.00
;------------------------------------------------------------------------------
;       Purpose: CoolTerm helper
;       Note(s): https://forums.the-meiers.org/viewtopic.php?f=4&t=541#
;                https://www.autohotkey.com/board/topic/84055-reopen-gui-at-position-it-was-last-closed/
;
;                Hotkeys (Mouse, Joystick and Keyboard Shortcuts)
;                https://autohotkey.com/docs/Hotkeys.htm
;                  !   Alt Key
;                  ^   Control Key (Ctrl)
;                  +   Shift Key
;                  #   WinKey (Windows logo key)
;==============================================================================
; Always run your script as admin
if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}
#SingleInstance force       ; Skips the dialog box and replaces the old instance
                            ; Automatically, which is similar in effect to the Reload command.
#NoEnv                      ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input              ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetBatchLines, 10ms

; read the saved positions / center if not previously saved
IniRead, gui_position, settings_cooltermmacros.ini, window position, gui_position, Center

Gui, New, +AlwaysOnTop, CoolTerm Macros 1.00
; get window ID
Gui, +Hwndgui_id
Gui, Font, s12, Consolas  ; Set 12-point Consolas
Gui, Add, Button, x6   y10   w100  h25 gH1, Edit AHK ;H1
Gui, Add, Button, x112 y10   w100  h25 gH2, CT On Top ;H2
Gui, Add, Button, x218 y10   w100  h25 gH3, - - - - - ;H3
;------------------------------------------------
Gui, Add, Button, x8   y50  w150 h25 gM1, M1: - - - - - ;M1
Gui, Add, Button, x8   y80  w150 h25 gM2, M2: - - - - - ;M2
Gui, Add, Button, x8   y110 w150 h25 gM3, M3: - - - - - ;M3

Gui, Add, Button, x166 y50  w150 h25 gM4, M4: - - - - - ;M4
Gui, Add, Button, x166 y80  w150 h25 gM5, M5: - - - - - ;M5
Gui, Add, Button, x166 y110 w150 h25 gM6, M6: - - - - - ;M6

; Show window at saved position
Gui, Show, %gui_position% w324, CoolTerm Macros 1.00
return

H1:
;Header Macro 1
;Edit THIS script
Run, "{YourEditorHere.exe}" "{path}\cooltermmacros.ahk"
return

H2:
;Header Macro 2
;Always On Top
WinActivate, ahk_exe CoolTerm.exe
Winset, Alwaysontop, , A
return

H3:
;Header Macro 3
return


M1:
WinActivate, ahk_exe CoolTerm.exe
;Macro 1
return

M2:
WinActivate, ahk_exe CoolTerm.exe
;Macro 2
return

M3:
WinActivate, ahk_exe CoolTerm.exe
;Macro 3
return

M4:
WinActivate, ahk_exe CoolTerm.exe
;Macro 4
return
M5:
WinActivate, ahk_exe CoolTerm.exe
;Macro 5
return
M6:
WinActivate, ahk_exe CoolTerm.exe
;Macro 6
return

;Close the window acquire and save position.
GuiClose:
WinGetPos, gui_x, gui_y,,, ahk_id %gui_id%
IniWrite, x%gui_x% y%gui_y%, settings_cooltermmacros.ini, window position, gui_position
ExitApp
User avatar
roger
Site Admin
Posts: 431
Joined: Fri Apr 24, 2009 12:41 am
Contact:

Re: CoolTerm Marcos using AutoHotKey

Post by roger »

Very nice! Thanks for sharing!

Roger
Post Reply