Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #NoEnv
- #SingleInstance, Force
- SendMode, Input
- SetBatchLines, -1
- SetCapsLockState, AlwaysOff
- EnvGet, ProgramFilesx86, ProgramFiles(x86)
- ; Menu
- Menu, caseChange, Add, &camelCase, caseC
- Menu, caseChange, Add, &lower case, caseL
- Menu, caseChange, Add, &Paragraph, caseP
- Menu, caseChange, Add, &Title Case, caseT
- Menu, caseChange, Add, &UPPER CASE, caseU
- Menu, caseChange, Add
- Menu, caseChange, Add, C&ancel, Cancel
- ; #1: Stay off unless activated with Win+Caps
- #CapsLock::SetCapsLockState, % GetKeyState("CapsLock", "T") ? "AlwaysOff" : "On"
- ; #2: ShareX commands
- Capslock & s::!F1
- Capslock & e::!F2
- Capslock & o::!F3
- Capslock & r::!F5
- Capslock & p::#+c
- ; #3: Searching online
- CapsLock & g::Run, % "https://www.google.com/search?q=" clip(1)
- CapsLock & d::Run, % "https://www.google.com/search?q=define+" clip(1)
- CapsLock & t::Run, % "https://www.thesaurus.com/browse/" clip(1)
- ; #4: Launching apps
- CapsLock & v::Run, % A_AppData "\..\Local\Vivaldi\Application\vivaldi.exe"
- CapsLock & n::Run, % A_AppData "\..\Local\Obsidian\Obsidian.exe"
- CapsLock & m::Run, % ProgramFilesx86 "\eM Client\MailClient.exe"
- ; #5: Case Changer
- ^CapsLock::Menu, caseChange, Show
- ; #6: Line editing
- Capslock & a::Send, {Home 2}+{End}
- Capslock & x::Send, {Home 2}+{End}^x
- Capslock & c::Send, {Home}{End}+!{5}
- ; #7: Markdown
- Capslock & /::wrap("```````n", "`n```````n`n")
- Capslock & k::
- Gui, New, +AlwaysOnTop -SysMenu, Add a link
- Gui, Add, Edit, VmdTxt w300, Title of link (optional)
- Gui, Add, Edit, VmdUri w300, % (Clipboard ~= "^(ftp|https?|mailto):" ? Clipboard : "Paste or type a link")
- Gui, Add, Button, Default x-100 y-100 -Tabstop, OK
- Gui, Show
- return
- ; #8: Text wrap
- CapsLock & h::wrap("<kbd>", "</kbd>")
- CapsLock & z::wrap("~~~~")
- CapsLock & b::wrap("**")
- CapsLock & i::wrap("*")
- CapsLock & ,::wrap("<", ">")
- CapsLock & [::wrap("[[", "]]")
- CapsLock & ]::wrap("{{", "}}")
- CapsLock & 9::wrap("(", ")")
- CapsLock & `::wrap("``", "``")
- CapsLock & '::wrap(Chr(34))
- CapsLock & -::Send, % "{Home 2}-" A_Space
- ; #9: Non-Caps Replacements and Hotstrings
- !-::Send, — ; Alt+Minus = Em dash
- +!-::Send, – ; Shift+Alt+Minus = En dash
- ::|c::©
- ::(c)::©
- ::|r::®
- ::(r)::®
- ::|s::§
- ::(tm)::™
- :c:|o::•
- ::|bull::•
- ::|bullet::•
- ; Arrows
- :?*:-->::→
- :?*:<--::←
- :?*:<->::↔
- ::|^::↑
- ::|v::↓
- clip(copy = 0, reset = -1)
- {
- static backup := ""
- if (copy)
- {
- backup := ClipboardAll
- Clipboard := ""
- if (copy = 1)
- {
- Send, ^c
- }
- else
- {
- Clipboard := copy
- }
- ClipWait, 1
- if (ErrorLevel)
- {
- MsgBox, 0x10,, Error getting Clipboard data.
- Exit
- }
- SetTimer, % A_ThisFunc, % reset
- return Clipboard
- }
- else
- {
- Sleep, 500
- Clipboard := backup
- }
- }
- wrap(before, after := "")
- {
- txt := clip(1, "Off")
- RegExMatch(txt, "\s+$", ews)
- out := before RTrim(txt) (after ? after : before) ews
- Clipboard := ""
- Clipboard := out
- ClipWait
- Send, ^v
- clip()
- }
- formatLink(txt, uri)
- {
- static chars := StrSplit("\*_{}[]<>()#+-.!|")
- ; https://www.markdownguide.org/basic-syntax#characters-you-can-escape
- if (!RegExMatch(uri, "^(ftp|https?|mailto):"))
- {
- return
- }
- start := InStr(uri, "/",,, 3)
- , txt := txt = "Title of link (optional)" ? "" : txt
- , uri := SubStr(uri, 1, start) encodeURI(decodeURI(SubStr(uri, start+1)))
- ; https://www.markdownguide.org/basic-syntax#link-best-practices
- if (!txt)
- {
- return "<" uri ">"
- }
- for i,chr in chars
- {
- txt := StrReplace(txt, chr, "\" chr)
- }
- return "[" txt "](" uri ")"
- }
- encodeURI(uri, encoding := "UTF-8")
- {
- out := ""
- VarSetCapacity(var, StrLen(uri) * 2, 0)
- StrPut(uri, &var, encoding)
- while (code := NumGet(var, A_Index - 1, "UChar"))
- {
- char := Chr(code)
- out .= (char ~= "[!#$&-;=?-Z_a-z~]" ? char : Format("%{:02X}", code))
- }
- return out
- }
- decodeURI(uri, encoding := "UTF-8")
- {
- while RegExMatch(uri, "i)(%[\dA-F]{2})+", code)
- {
- VarSetCapacity(var, 2, 0)
- loop, parse, % SubStr(code, 2), `%
- {
- NumPut("0x" A_LoopField, var, A_Index-1, "UChar")
- }
- uri := StrReplace(uri, code, StrGet(&var, encoding))
- }
- return uri
- }
- ButtonOK:
- Gui, Submit
- if (link := formatLink(mdTxt, mdUri))
- {
- clip(link)
- Send, ^v
- }
- GuiEscape:
- Gui, Destroy
- return
- caseC:
- caseL:
- caseP:
- caseT:
- caseU:
- txt := clip(1, "Off")
- switch mode := SubStr(A_ThisLabel, 0)
- {
- case "C": txt := RegExReplace(txt, "(([A-Z]+)|(?i)((?<=[a-z])|[a-z])([a-z]*))[ _-]([a-z]|[A-Z]+)", "$L2$L3$4$T5")
- case "P": txt := RegExReplace(txt, "(\w)([^?.:!]*)", "$U1$L2")
- Default: txt := Format("{:" mode "}", txt)
- }
- Clipboard := txt
- Send, ^v
- clip()
- Cancel:
- return
- ;
- ; Hotstring Helper
- ; https://www.autohotkey.com/docs/Hotstrings.htm#Helper
- ;
- #h:: ; Win+H hotkey
- ; Get the text currently selected. The clipboard is used instead of
- ; "ControlGet Selected" because it works in a greater variety of editors
- ; (namely word processors). Save the current clipboard contents to be
- ; restored later. Although this handles only plain text, it seems better
- ; than nothing:
- AutoTrim Off ; Retain any leading and trailing whitespace on the clipboard.
- ClipboardOld := ClipboardAll
- Clipboard := "" ; Must start off blank for detection to work.
- Send ^c
- ClipWait 1
- if ErrorLevel ; ClipWait timed out.
- return
- ; Replace CRLF and/or LF with `n for use in a "send-raw" hotstring:
- ; The same is done for any other characters that might otherwise
- ; be a problem in raw mode:
- StringReplace, Hotstring, Clipboard, ``, ````, All ; Do this replacement first to avoid interfering with the others below.
- StringReplace, Hotstring, Hotstring, `r`n, ``r, All ; Using `r works better than `n in MS Word, etc.
- StringReplace, Hotstring, Hotstring, `n, ``r, All
- StringReplace, Hotstring, Hotstring, %A_Tab%, ``t, All
- StringReplace, Hotstring, Hotstring, `;, ```;, All
- Clipboard := ClipboardOld ; Restore previous contents of clipboard.
- ; This will move the input box's caret to a more friendly position:
- SetTimer, MoveCaret, 10
- ; Show the input box, providing the default hotstring:
- InputBox, Hotstring, New Hotstring, Type your abreviation at the indicated insertion point. You can also edit the replacement text if you wish.`n`nExample entry: :R:btw`::by the way,,,,,,,, :R:`::%Hotstring%
- if ErrorLevel ; The user pressed Cancel.
- return
- if InStr(Hotstring, ":R`:::")
- {
- MsgBox You didn't provide an abbreviation. The hotstring has not been added.
- return
- }
- ; Otherwise, add the hotstring and reload the script:
- FileAppend, `n%Hotstring%, %A_ScriptFullPath% ; Put a `n at the beginning in case file lacks a blank line at its end.
- Reload
- Sleep 200 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
- MsgBox, 4,, The hotstring just added appears to be improperly formatted. Would you like to open the script for editing? Note that the bad hotstring is at the bottom of the script.
- IfMsgBox, Yes, Edit
- return
- MoveCaret:
- if not WinActive("New Hotstring")
- return
- ; Otherwise, move the input box's insertion point to where the user will type the abbreviation.
- Send {Home}{Right 3}
- SetTimer, MoveCaret, Off
- return
- ;
- ; Start of auto-generated content by Hotstring Helper
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement