Skip to content

Instantly share code, notes, and snippets.

@motionharvest
Created December 30, 2025 13:12
Show Gist options
  • Select an option

  • Save motionharvest/0eb570a8a746eb55f416967935bc6e30 to your computer and use it in GitHub Desktop.

Select an option

Save motionharvest/0eb570a8a746eb55f416967935bc6e30 to your computer and use it in GitHub Desktop.
Capslock + Space autohotkey script for carrot insert AI answer
#Requires AutoHotkey v2.0
#SingleInstance Force
CapsLock::return
CapsLock & Space::
{
prompt := AskPalette()
if (prompt = "")
return
StartSpinner()
answer := AskOpenAI(prompt)
StopSpinner()
if (answer = "")
return
SendText(answer)
}
global _spinnerFrames := ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"]
global _spinnerIndex := 1
global _spinnerGui := 0
global _spinnerText := 0
StartSpinner() {
global _spinnerIndex
_spinnerIndex := 1
CreateSpinnerGui()
SetTimer(SpinnerTick, 80)
}
StopSpinner() {
SetTimer(SpinnerTick, 0)
DestroySpinnerGui()
}
SpinnerTick() {
global _spinnerFrames, _spinnerIndex, _spinnerText, _spinnerGui
if !_spinnerText
return
_spinnerText.Value := _spinnerFrames[_spinnerIndex]
MouseGetPos &mx, &my
_spinnerGui.Show("NoActivate x" (mx + 12) " y" (my + 12))
_spinnerIndex++
if (_spinnerIndex > _spinnerFrames.Length)
_spinnerIndex := 1
}
IsWindowsDarkMode() {
try {
val := RegRead(
"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize",
"AppsUseLightTheme"
)
return (val = 0)
}
catch {
return false
}
}
AskPalette() {
result := ""
g := Gui("+AlwaysOnTop -Caption +ToolWindow")
g.MarginX := 6
g.MarginY := 6
; Create edit with default system colors first
edt := g.AddEdit("w520 r1 -Border")
g.MarginX := 14
g.MarginY := 12
edt.SetFont("s11")
; Apply dark styling only if Windows is in dark mode
if IsWindowsDarkMode() {
g.BackColor := "1E1E1E"
edt.Opt("+Background1E1E1E") ; IMPORTANT: edit background
edt.SetFont("s11 cWhite") ; edit text color
}
MouseGetPos &mx, &my
g.Show("AutoSize Center")
hwnd := g.Hwnd
HotIfWinActive("ahk_id " hwnd)
Hotkey("Enter", (*) => (result := edt.Value, WinClose("ahk_id " hwnd)), "On")
Hotkey("Esc", (*) => WinClose("ahk_id " hwnd), "On")
HotIfWinActive()
WinWaitClose(hwnd)
HotIfWinActive("ahk_id " hwnd)
Hotkey("Enter", "Off")
Hotkey("Esc", "Off")
HotIfWinActive()
return Trim(result)
}
CreateSpinnerGui() {
global _spinnerGui, _spinnerText
if _spinnerGui
return
_spinnerGui := Gui("+AlwaysOnTop -Caption +ToolWindow +E0x20")
_spinnerGui.MarginX := 6
_spinnerGui.MarginY := 4
_spinnerText := _spinnerGui.AddText("w20 Center", "⠋")
_spinnerText.SetFont("s12")
if IsWindowsDarkMode() {
_spinnerGui.BackColor := "1E1E1E"
_spinnerText.SetFont("cWhite")
}
MouseGetPos &mx, &my
_spinnerGui.Show("NoActivate AutoSize x" (mx + 12) " y" (my + 12))
}
DestroySpinnerGui() {
global _spinnerGui, _spinnerText
if _spinnerGui {
_spinnerGui.Destroy()
_spinnerGui := 0
_spinnerText := 0
}
}
AskOpenAI(prompt) {
out := A_Temp "\ai_insert_out.txt"
if FileExist(out)
FileDelete(out)
psFile := A_ScriptDir "\ai_call.ps1"
if !FileExist(psFile)
return ""
cmd := 'powershell -NoProfile -ExecutionPolicy Bypass -File "' psFile '"'
cmd .= ' -Prompt ' QuoteArg(prompt)
cmd .= ' -Selection ""'
cmd .= ' -OutFile "' out '"'
RunWait(cmd, , "Hide")
if !FileExist(out)
return ""
return Trim(FileRead(out, "UTF-8"))
}
QuoteArg(s) {
return '"' StrReplace(s, '"', '\"') '"'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment