public
Last active

AutoHotkey_L Hotstrings and other utilities

  • Download Gist
AutoHotkey.ahk
AutoHotkey
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
;------------------------------------------------------------------------------
; Disable Insert key
;------------------------------------------------------------------------------
$Insert::return
!Insert::Send, {Insert} ; Use Alt+Insert to toggle the 'Insert mode'
 
;------------------------------------------------------------------------------
; Hand tool with middle button in Adobe Reader
;------------------------------------------------------------------------------
#IfWinActive ahk_class AdobeAcrobat
Mbutton::
#IfWinActive ahk_class AcrobatSDIWindow
Mbutton::
#IfWinActive ahk_class DSUI:PDFXCViewer
Mbutton::
Send {Space down}{LButton down} ; Hold down the left mouse button.
KeyWait Mbutton ; Wait for the user to release the middle button.
Send {LButton up}{Space up} ; Release the left mouse button.
return
#IfWinActive
 
;------------------------------------------------------------------------------
; Hand tool with middle button in Sumatra PDF
;------------------------------------------------------------------------------
#IfWinActive ahk_class SUMATRA_PDF_FRAME
Mbutton::
Send {RButton down} ; Hold down the left mouse button.
KeyWait Mbutton ; Wait for the user to release the middle button.
Send {RButton up} ; Release the left mouse button.
return
#IfWinActive
 
;------------------------------------------------------------------------------
; Ctrl+Q closes Firefox
;------------------------------------------------------------------------------
#IfWinActive ahk_class MozillaWindowClass
^q::
Send !f
Send !x
return
#IfWinActive
 
;------------------------------------------------------------------------------
; Ctrl+W closes tabs in IAR compiler or TINA-TI
;------------------------------------------------------------------------------
#IfWinActive IAR Embedded Workbench IDE
^w::
#IfWinActive ahk_class TSchematicEditor
^w::
Send ^{F4}
return
#IfWinActive
 
;------------------------------------------------------------------------------
; WINDOWS KEY + H TOGGLES HIDDEN FILES
; from http://www.howtogeek.com/howto/keyboard-ninja/keyboard-ninja-toggle-hidden-files-with-a-shortcut-key-in-windows/
;------------------------------------------------------------------------------
#h::
RegRead, HiddenFiles_Status, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden
If HiddenFiles_Status = 2
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1
Else
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2
WinGetClass, eh_Class,A
If (eh_Class = "#32770" OR A_OSVersion = "WIN_VISTA" OR A_OSVersion = "WIN_7")
send, {F5}
Else PostMessage, 0x111, 28931,,, A
Return
 
;------------------------------------------------------------------------------
; WINDOWS KEY + Y TOGGLES FILE EXTENSIONS
; from http://www.howtogeek.com/howto/windows-vista/keyboard-ninja-toggle-file-extension-display-with-a-shortcut-key-in-windows/
;------------------------------------------------------------------------------
#y::
RegRead, HiddenFiles_Status, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt
If HiddenFiles_Status = 1
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt, 0
Else
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt, 1
WinGetClass, eh_Class,A
If (eh_Class = "#32770" OR A_OSVersion = "WIN_VISTA" OR A_OSVersion = "WIN_7")
send, {F5}
Else PostMessage, 0x111, 28931,,, A
Return
 
;------------------------------------------------------------------------------
; Google text from any app
; from http://superuser.com/questions/7271/most-useful-autohotkey-scripts/165220#165220
;------------------------------------------------------------------------------
#s::
MyClip := ClipboardAll
Clipboard = ; empty the clipboard
Send, ^c
ClipWait, 2
if ErrorLevel ; ClipWait timed out.
{
return
}
if RegExMatch(Clipboard, "^(https?://|www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$")
{
Run % Clipboard
}
else
{
; Modify some characters that screw up the URL
; RFC 3986 section 2.2 Reserved Characters (January 2005): !*'();:@&=+$,/?#[]
StringReplace, Clipboard, Clipboard, `r`n, %A_Space%, All
StringReplace, Clipboard, Clipboard, #, `%23, All
StringReplace, Clipboard, Clipboard, &, `%26, All
StringReplace, Clipboard, Clipboard, +, `%2b, All
StringReplace, Clipboard, Clipboard, ", `%22, All
Run % "http://www.google.com/#hl=en&q=" . clipboard ; uriEncode(clipboard)
}
Clipboard := MyClip
return
 
;------------------------------------------------------------------------------
; Google translate selected text
;------------------------------------------------------------------------------
#g::
MyClip := ClipboardAll
Clipboard = ; empty the clipboard
Send, ^c
ClipWait, 2
if ErrorLevel ; ClipWait timed out.
{
return
}
StringReplace, Clipboard, Clipboard, `%, `%25, All ; has to come first
StringReplace, Clipboard, Clipboard, `r`n, `%0A, All
Run % "http://translate.google.com/#auto|en|" . clipboard ; uriEncode(clipboard)
Clipboard := MyClip
return
 
;------------------------------------------------------------------------------
; Shortcuts that do not fall under misspellings or typos
; (otherwise in AutoCorrect.ahk)
;------------------------------------------------------------------------------
 
; c = case sensitive
; c1 = ignore the case that was typed, always use the same case for output
; * = immediate change (no need for space, period, or enter)
; ? = triggered even when the character typed immediately before it is alphanumeric
; r = raw output
 
; Thunderbird autocorrect uses |c → ©, MS Word uses (c) → ©
; I don't know where | prefix comes from, but I am also adopting it as an
; "escape character" for literal symbols that might otherwise want to be
; written out. "pi" vs "π". for instance. Could also use ~ or something.
 
; Alternately, HTML entity references like "asymp" that are not otherwise words can safely be used alone?
; en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_entity_references_in_HTML
; But it's easier to just use the pipe character, so I've largely abandoned this
 
;------------------------------------------------------------------------------
; Science/engineering
;------------------------------------------------------------------------------
; Resistances using Greek uppercase omega character, not
; Unicode ohm sign (which only exists for backwards compatibility)
:c1*:kohm::kΩ ; kiloohm
:c1*:okhm::kΩ ; kiloohm
:c1*:mohm::MΩ ; megaohm
:c1*:gohm::GΩ ; gigaohm
:c1*:tohm::TΩ ; teraohm
:*:|ohm::Ω
; :*:ohm::Ω ; not sure if want
; :*:ohms::Ω
 
; micro- prefix using Unicode micro sign (µ), not mu character (μ)
:c*:uA::µA ; microamp
:c*:uF::µF ; microfarad
:c*:uH::µH ; microhenry - needs to be case sensitive - "uh" is a word
:c*:uV::µV ; microvolt
:c*:uW::µW ; microwatt
:c*:uPa::µPa ; micropascal
:*:|um::µm
::microm::µm ; micrometer or micron
:*:|micron::µm
:*:|us::µs ; microsecond
:*:usec::µs
:*c:uS::µS ; microsiemens
 
; :c*:MWe::MWₑ ; Probably a bad idea
 
:c1:pf::pF ; picofarad
:c1:nf::nF ; nanofarad
; :c:mv::mV ; millivolt - conflicts with bash command
:c:nv::nV ; nanovolt
:*?:degC::°C ; degrees Celsius
:*?:degF::°F ; degrees Fahrenheit
:*?:|deg::° ; degree symbol
:*:rthz::Hz ; square root of hertz
:r:thdn::THD+N ; total harmonic distortion and noise
::|diam:: ; diameter symbol - alternately could be "Latin small letter o with stroke" (ø) if no font support
::m^2::m² ; Maybe a bad idea
; ::1/4"::¼" ; Probably a bad idea
; ::1/4"::¼″ ; technically should be a double prime
 
; add Unicode non-breaking spaces before units? or is that too pedantic?
 
;------------------------------------------------------------------------------
; Math
;------------------------------------------------------------------------------
:?*:+-::± ; plus-or-minus sign
:?:|-:: ; true minus sign
:?:|minus:: ; true minus sign
:?:|x::× ; true times sign
:?:|times::×
::divby::÷ ; division sign or obelus
::./.::÷ ; any conflicts?
:?:|*:: ; "dot operator" (⋅), for multiplication, dot product
 
; sdot ⋅ U+22C5 HTMLsymbol dot operator ('dot operator' is NOT the same character as U+00B7 'middle dot'.)
 
; Experimental:
:?:1x::1×
:?:2x::2×
:?:3x::3×
:?:4x::4×
:?:5x::5×
:?:6x::6×
:?:7x::7×
:?:8x::8×
:?:9x::9×
 
; "Unicode also includes a handful of vulgar fractions as compatibility characters, but discourages their use."
::|1/2::½
::|1/4::¼
::|3/4::¾
 
 
::|>=:: ; '>=' conflicts with usage in programming. Alternatively, it could specify different rules for code windows.
::|<=::
::|!=:: ; not equal to
::|>>:: ; much greater than
::|<<:: ; much less than
::|!=::
::notequal::
::approx:: ; approximately equal to
::asymp::
::|~::
::|propto:: ; proportional to
::|=-:: ; mathematical identity
::|===::
::|propersubset:: ; SUBSET OF
::|propersuperset:: ; SUPERSET OF
::|notsubset:: ; NOT A SUBSET OF
::|subset:: ; SUBSET OF OR EQUAL TO
::|superset:: ; SUPERSET OF OR EQUAL TO
 
; superscripts and subscripts from HTML entity names sup2 and sup3
; Examples: km² V₊ V₋ CuSO₄·5H₂O or ²³⁸U (hard to type, ugly, but actually used, according to Google)
; Alternate notation: x^2 → x², x_2 → x₂
; Of course, that would conflict with programming variable names like max_3
; There's also ⁼⁽⁾₌₍₎ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖʳˢᵗᵘᵛʷˣʸᶻᴬᴮᴰᴱᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾᴿᵀᵁⱽᵂₐₑₕᵢₖₗₘₙₒₚᵣₛₜᵤᵥₓᵅᵝᵞᵟᵋᶿᶥᶲᵠᵡᵦᵧᵨᵩᵪ
:?:sup0::
:?:sup1::¹
:?:sup2::² ; common
:?:sup3::³ ; common
:?:sup4::
:?:sup5::
:?:sup6::
:?:sup7::
:?:sup8::
:?:sup9::
:?:sup+::
:?:sup-::
:?:supn::
:?:supi::
 
:?:sub0::
:?:sub1::
:?:sub2::
:?:sub3::
:?:sub4::
:?:sub5::
:?:sub6::
:?:sub7::
:?:sub8::
:?:sub9::
:?:sub+::
:?:sub-::
 
::|sqrt:: ; square root
::radic::
::|inf::
 
; Greek characters for math, etc.
:C:|Alpha::Α
:C:|Beta::Β
:C:|Gamma::Γ
:C:|Delta::Δ
:C:|Epsilon::Ε
:C:|Zeta::Ζ
:C:|Eta::Η
:C:|Theta::Θ
:C:|Iota::Ι
:C:|Kappa::Κ
:C:|Lambda::Λ
:C:|Mu::Μ
:C:|Nu::Ν
:C:|Xi::Ξ
:C:|Omicron::Ο
:C:|Pi::Π
:C:|Rho::Ρ
:C:|Sigma::Σ
:C:|Tau::Τ
:C:|Upsilon::Υ
:C:|Phi::Φ
:C:|Chi::Χ
:C:|Psi::Ψ
:C*:|Omega::Ω
:C:|alpha::α
:C:|beta::β
:C:|gamma::γ
:C:|delta::δ
:C:|epsilon::ε
:C:|zeta::ζ
:C:|eta::η
:C:|theta::θ
:C:|iota::ι
:C:|kappa::κ
:C:|lambda::λ
:C:|mu::μ
:C:|nu::ν
:C:|xi::ξ
:C:|omicron::ο
:C?:|pi::π
:C:|rho::ρ
:C:|sigmaf::ς
:C:|sigma::σ
:C:|tau::τ
:C:|upsilon::υ
:C:|phi::φ
:C:|chi::χ
:C:|psi::ψ
:C*:|omega::ω
:C*:|thetasym::ϑ
:C:|upsih::ϒ
:C:|piv::ϖ
 
;------------------------------------------------------------------------------
; Typography / symbols
;------------------------------------------------------------------------------
::|c::© ; copyright symbol
::(c)::©
::|r::® ; registered symbol
::(r)::®
::|s::§ ; section symbol
::(tm):: ; trademark symbol
 
:c:|o:: ; bullet
::|bull::
::|bullet::
:c:|O:: ; black circle
::|():: ; white circle
 
; these don't work due to minus sign. needs to ignore dashes as closing characters for just these. also hard to remember since -- is usually em.
;::|--::– ; en dash –
;::|---::— ; em dash —
::|en::
::|em::
; ¦ ; broken bar
:?*:|cent::¢ ; cents symbol
 
; middot · U+00B7 HTMLlat1 middle dot (= Georgian comma = Greek middle dot)
:?:|.::· ; "middle dot" (&middot;), for interword separation, punctuation, ???
::|...:: ; Doesn't work due to above
 
; Arrows
:?*:-->::
:?*:==>::
:?*:<--::
:?*:<==::
:?*:<->::
:?*:<=>::
::|^::
::|v::
 
; Special characters
;:r:|nbsp:: ; Doesn't work?
 
;------------------------------------------------------------------------------
; Emoticons
;------------------------------------------------------------------------------
::0_0::_ ; look of disapproval
::|<3::
::(:))::
::|:)::
::(:()::
::|:(::
::|snowman::
::|skull::
::|music::♪♫
:r:|hug::(>^_^)> <(^.^<)
::|nerd::_
 
;------------------------------------------------------------------------------
; HTML shortcuts
;------------------------------------------------------------------------------
:*b0:|bq::{bs 3}<blockquote></blockquote>{left 13}
; :*:|bq::<blockquote>
:*:|/bq::</blockquote>
:*:|\bq::</blockquote>
 
:*b0:|qu::{bs 3}[QUOTE][/QUOTE]{left 8}
:*:|/qu::[/QUOTE]
:*:|\qu::[/QUOTE]
 
:*b0:<em>::</em>{left 5}
 
;------------------------------------------------------------------------------
; Insert timestamp
;------------------------------------------------------------------------------
; Should be a keyboard shortcut or a phrase?
; Needs to be compatible with spreadsheet formats
 
+!d:: ;Shift-Alt-D: Insert current date and time stamp
FormatTime, T, %A_Now%, yyyy-MM-dd hh:mm:ss tt ; 2012-01-24 10:54:31 PM - works in LibreOffice, Google Spreadsheet, Excel
SendInput %T%
return
 
::|date:: ;Insert current date
FormatTime, T, %A_Now%, yyyy-MM-dd ; 2011-07-25
SendInput %T%
return
 
::|time:: ;Insert current time
FormatTime, T, %A_Now%, hh:mm:sstt ; 09:24:20AM
SendInput %T%
return
 
;------------------------------------------------------------------------------
; Make windows transparent
;------------------------------------------------------------------------------
#T::
DetectHiddenWindows, on
WinGet, curtrans, Transparent, A
if ! curtrans
curtrans = 255
newtrans := curtrans - 64
if newtrans > 0
{
WinSet, Transparent, %newtrans%, A
 
}
else
{
WinSet, Transparent, 255, A
WinSet, Transparent, OFF, A
}
return
 
#w::
DetectHiddenWindows, on
WinSet, TransColor, Black 128, A
return
 
#o::
WinSet, Transparent, 255, A
WinSet, Transparent, OFF, A
return
 
#g:: ; Press Win+G to show the current settings of the window under the mouse.
MouseGetPos,,, MouseWin
WinGet, Transparent, Transparent, ahk_id %MouseWin%
WinGet, TransColor, TransColor, ahk_id %MouseWin%
ToolTip Translucency:`t%Transparent%`nTransColor:`t%TransColor%
return
 
;------------------------------------------------------------------------------
; Win+V: Paste as plain text from clipboard
;------------------------------------------------------------------------------
#v::
Clip0 = %ClipBoardAll%
ClipBoard = %ClipBoard% ; Convert to plain text
Send ^v ; For best compatibility: SendPlay
Sleep 50 ; Don't change clipboard while it is pasted! (Sleep > 0)
ClipBoard = %Clip0% ; Restore original ClipBoard
VarSetCapacity(Clip0, 0) ; Free memory
Return
 
;------------------------------------------------------------------------------
; Win+Alt+V: Paste plain text only, stripping characters unsafe for filenames
;------------------------------------------------------------------------------
#!v:: ; paste without formatting
StringReplace, clipboardt, clipboard, `r`n, %A_Space%, All
clipboardt := RegExReplace(clipboardt, "` {2,}", "` ")
StringLeft, 1st, clipboardt, 1
IfInString, 1st, %A_Space%
StringTrimLeft, clipboardt, clipboardt, 1
StringRIght, last, clipboardt, 1
IfInString, last, %A_Space%
StringTrimRight, clipboardt, clipboardt, 1
;Send {Raw}%clipboardt%
Clip0 = %ClipBoardAll%
ClipBoard = %clipboardt% ; Convert to plain text
Send ^v ; For best compatibility: SendPlay
Sleep 50 ; Don't change clipboard while it is pasted! (Sleep > 0)
ClipBoard = %Clip0% ; Restore original ClipBoard
VarSetCapacity(Clip0, 0) ; Free memory
clipboardt =
return
readme.md
Markdown

My AutoHotkey shortcuts and helper scripts. (For the Unicode-aware AutoHotkey_L)

Special character shortcuts

I'm an electrical engineer and generally math/science-type person, so I've made a lot of shortcuts for typing special characters. This is the best way I've found to do this. Works in every text field in every application, and is much faster and easier than copying and pasting them or looking them up in a character map. (And stop using the Symbol font, people! Your "kΩ" are turning into "kW" whenever I copypaste them!)

Example: If you type:

5 |x 10sup7 kohm+-1% 3 nv/rthz 100degc 220 uF

it becomes:

5 × 10⁷ kΩ±1% 3 nV/√Hz 100°C 220 µF

So useful.

Thunderbird Auto Correct extension uses things like |c©, so I've adopted this convention for other special characters. |piπ, |<3, |:), |snowman, etc. Easier to remember than Unicode code points or Alt codes, pretty easy to type, and doesn't conflict with named HTML entities, etc. There might be a better initial character to use, but I haven't had any problems with | yet.

To do / wish list

  • Unify scroll wheel direction and zoom/drag functions across all applications
    • Inverting scroll wheel unfortunately inverts it for all parts of that app, not just the main view, but lists and stuff, too.
  • Disable shortcuts for Python terminals, PuTTY, etc.
    • #IfWinNotActive with source code extensions at the end, to disable shortcuts like <= that would conflict with writing code?
  • Automatically use newline-stripping paste if pasting into filename fields?
  • Hold down Caps Lock to emulate Archy leaping navigation?
  • or Caps Lock should act as a shift? Unless you hit it twice consecutively, or press Shift+Caps Lock
  • If Caps Lock is already pressed, and I press Shift, it should undo Caps Lock?
  • or it should just detect words sPELLED lIKE tHIS.
  • Simple calculator: Press some keyboard shortcut, dialog pops up, type in 4553+3243 and press Enter, and it pastes 7796 into your document.
  • Toggle UPPERCASE, lowercase, Title Case, etc for selected text in any app
zzz abandoned.ahk
AutoHotkey
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
; I don't use these anymore.
 
;------------------------------------------------------------------------------
; Change scroll behavior in Protel
;------------------------------------------------------------------------------
; I never use this anymore - Altium Designer has a better interface
#IfWinActive ahk_class Design Explorer 99 SE Main Window
WheelUp::send, {PgUp}
WheelDown::send, {PgDn}
Mbutton::Send {Home}
;Mbutton::
;{
; Loop
; {
; Sleep, 10
; GetKeyState, state, Mbutton, P
; if state = U ; The key has been released, so break out of the loop.
; break
; Send {Home}
; }
;}
#IfWinActive
 
 
;------------------------------------------------------------------------------
; Change scroll wheel behavior in Adobe Illustrator
;------------------------------------------------------------------------------
; I never use this now that I know Adobe Reader can handle .ai files
#IfWinActive ahk_class Illustrator9
WheelUp::send, ^=
WheelDown::send, ^-
Mbutton::
Send {Space down}{LButton down} ; Hold down the left-arrow key.
KeyWait Mbutton ; Wait for the user to release the middle button.
Send {LButton up}{Space up} ; Release the left-arrow key.
return
#IfWinActive

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.