- Aug
- 2,831
- 149
First off,
there are of course better ways to do math from a text editor.
This was just an exercise,
to see if it could be done.
When I am in my text editor, I type;
The .calc activates the AutoHotKey code,
I'm not checking to make sure that tcc.exe is available,
nor am I doing much error checking at all.
As I said,
This was just an exercise,
to see if it could be done.
Joe
there are of course better ways to do math from a text editor.
This was just an exercise,
to see if it could be done.
When I am in my text editor, I type;
Code:
164.54 - 124.45 .calc
The .calc activates the AutoHotKey code,
- highlighting the mathematical expression
- copying it to the clipboard
- switching to TCC.EXE
- typing a :
- pasting the mathematical expression from the clipboard
- pressing the Ctrl-Enter keyboard combination
- which copies the answer to the clipboard
- switch back to my text editor
- and then over-write the highlighted mathematical expression with the answer.
Code:
; AutoHotkey v2 - use .calc to evaluate via Take Command (tcc.exe)
; Requires CMath from the EditKeys Plugin
; https://charlesdye.net/plugins/editkeys.html
;
; I use RightNote as my text editor
; https://www.bauerapps.com/rightnote/
:*:.calc::
{
; Only run inside RightNote
if !WinActive("ahk_exe RightNote.exe")
return
; Remove the typed trigger ".calc"
Send("{Backspace}")
Sleep 60
; Select from cursor to start of the line
Send("{Shift down}{Home}{Shift up}")
Sleep 60
Send("^c")
tccWin := WinExist("ahk_exe tcc.exe")
WinActivate(tccWin)
Sleep 100
; Type ":" then Shift+Insert to paste, then Ctrl+Enter to evaluate
Send(":")
Sleep 40
Send("{Shift down}{Insert}{Shift up}")
Sleep 40
Send("{Ctrl down}{Enter}{Ctrl up}")
Sleep 100
WinActivate("ahk_exe RightNote.exe")
WinWaitActive("ahk_exe RightNote.exe", 2)
Sleep 80 ; Paste the result (replaces the highlighted expression)
Send("^v")
}
I'm not checking to make sure that tcc.exe is available,
nor am I doing much error checking at all.
As I said,
This was just an exercise,
to see if it could be done.
Joe