Terminal Connectivity in Windows using Console

This HowTo documents how to integrate Geany with Console using AutoHotKey in Windows. This is useful since the terminal emulation feature is absent in geany on windows. Console is a tabbed wrapper for terminal-like programs in windows, and can be used as a shell to run anything from cmd.exe, python, rterm, etc. to Midnight Commander. AutoHotKey is a scripting language and interpreter that specializes in process management and keyboard shortcuts.

Setup

  • Download and install Console 2.0 and AutoHotKey.
  • Configure Console's tabs. To run shells other than cmd.exe, just go to Edit > Settings > Tabs. From here add another tab using Add and provide an appropriate function in the shell option.
  • Create the file AutoHotKey.ahk in your 'My Documents' folder. Alternatively, running AutoHotKey.exe will automatically generate this file. Just delete the contents.
  • Paste the following script into the file, replacing the path on line 5 with your path to Console, and the argument DefaultTab with the name of the tab you specified in Console:
AutoHotKey.ahk
TestConsole()
{
	IfWinNotExist, ahk_class Console_2_Main,
	{
		Run, C:\path\to\Console.exe -t DefaultTab
		WinWait, ahk_class Console_2_Main,
	}
}
 
ActivateConsole()
{
	TestConsole()
	WinActivate, ahk_class Console_2_Main,
	WinWaitActive, ahk_class Console_2_Main,
}
 
#1::
WinGetActiveTitle, editor
old_clipboard = %clipboard%
Send, {CTRLDOWN}c{CTRLUP}
ActivateConsole()
Send, {CTRLDOWN}{END}{CTRLUP}{RETURN}
WinActivate, %editor%,
clipboard = %old_clipboard%
return
 
#2::
WinGetActiveTitle, editor
old_clipboard = %clipboard%
Send, {HOME}{HOME}{SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}
ActivateConsole()
Send, {CTRLDOWN}{END}{CTRLUP}{RETURN}
WinActivate, %editor%,
clipboard = %old_clipboard%
WinWaitActive, %editor%,
Send, {HOME}{DOWN}
return
 
#3::
WinGetActiveTitle, editor
old_clipboard = %clipboard%
Send, {CTRLDOWN}ac{CTRLUP}
ActivateConsole()
Send, {CTRLDOWN}{END}{CTRLUP}{RETURN}
WinActivate, %editor%,
clipboard = %old_clipboard%
return

This script, when run, will bind the following commands:

  • Windows Key + 1: Pass highlighted text to Console.
  • Windows Key + 2: Pass current line to Console.
  • Windows Key + 3: Pass whole file to Console.
  • All of these will also open Console to your specified tab if it is not open.

To change these bindings, replace the #1, #2, or #3 in the above script with bindings that can be found here.

Print/export