Skip to content

Instantly share code, notes, and snippets.

@endolith
Last active August 28, 2025 16:20
Show Gist options
  • Save endolith/ad36f76f40e891a18a1f3c5ca6432280 to your computer and use it in GitHub Desktop.
Save endolith/ad36f76f40e891a18a1f3c5ca6432280 to your computer and use it in GitHub Desktop.
Qalculate keyboard shortcut with AutoHotkey

Qalculate Hotkey for inline calculations

Finally Qalculate has been ported to Windows. Now we can do unit-aware calculations inline, in any document, with AutoHotkey, similar to Monster.ahk but with units.

Instructions:

  1. Install Qalculate
  2. Install AutoHotkey
  3. Add qalc.exe to your PATH. I use Rapid Environment Editor for this.
  4. Run qalc.ahk

To use it:

  1. Select some text, such as 1/(2*pi*10 kohm * 390 pF)
  2. Press Win+Q
  3. It pastes the output of the calculation, such as 1 / (2 * pi * (10 kiloohms) * (390 picofarads)) = approx. 40.80895977 kHz.

Qalculate's interpretation of your input is also included, so you can verify it understood the input correctly.

To do

  • Should have separate keyboard shortcuts for including the original text or not? Like how Monster.ahk has Ctrl+Win+- for replacement, and Ctrl+Win+= for appending = and the result.
; This file must be saved with UTF-8-BOM encoding to work correctly.
; Custom icon from http://www.famfamfam.com/lab/icons/silk/preview.php
; Converted from PNG to ICO
Menu, Tray, Icon, application-x-qalculate.ico
#NoEnv ; For security
; Avoids checking empty variables to see if they are environment variables (recommended for all new scripts).
#SingleInstance force
#q::
Clipboard= ; this line must be after the Win+Q or it won't get executed and the ClipWait has no effect
Send ^c
ClipWait, 1 ; put a timeout so it doesn't get stuck if invoked with empty clipboard
if ErrorLevel ; if timeout
return
OriginalClip := Clipboard ; Store the original clipboard content
Myclip := Clipboard
Myclip := StrReplace(Myclip, Chr(0x2126), "ohm") ; Replace ohm sign (U+2126, Ω) with ohm
Myclip := StrReplace(Myclip, Chr(0x03A9), "ohm") ; Replace uppercase omega character (U+03A9, Ω) with ohm
; Replace superscript numbers with regular exponent notation
Myclip := StrReplace(Myclip, "⁰", "^0")
Myclip := StrReplace(Myclip, "¹", "^1")
Myclip := StrReplace(Myclip, "²", "^2")
Myclip := StrReplace(Myclip, "³", "^3")
Myclip := StrReplace(Myclip, "⁴", "^4")
Myclip := StrReplace(Myclip, "⁵", "^5")
Myclip := StrReplace(Myclip, "⁶", "^6")
Myclip := StrReplace(Myclip, "⁷", "^7")
Myclip := StrReplace(Myclip, "⁸", "^8")
Myclip := StrReplace(Myclip, "⁹", "^9")
RunWait, cmd.exe /c qalc "%Myclip%" | clip,,hide
Clipboard := RegExReplace(Clipboard, "\R", "") ; Remove newline characters from the result
SendRaw % OriginalClip " = " Clipboard ; Use OriginalClip instead of Myclip
Sleep, 500 ; must wait to give time to paste before clearing clipboard
Clipboard=
return ; really should have this, especially if other code follows
@endolith
Copy link
Author

@therealergo I've made some more changes since then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment