Advertisement
Guest User

AKH Caps

a guest
Jun 20th, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv
  2. #SingleInstance, Force
  3.  
  4. SendMode, Input
  5. SetBatchLines, -1
  6. SetCapsLockState, AlwaysOff
  7. EnvGet, ProgramFilesx86, ProgramFiles(x86)
  8.  
  9. ; TOC & Functionality:
  10. ; - Deactivates capslock for normal (accidental) use.
  11. ; - Hold Capslock and drag anywhere in a window to move it (not just the title bar).
  12. ; - Access the following functions when pressing Capslock:
  13. ;     Cursor keys           - J, K, L, I
  14. ;     Enter                 - Space
  15. ;     Home, PgDn, PgUp, End - (IN PROGRESS)
  16. ;     Backspace and Del     - N, M
  17. ;
  18. ;     Insert                - B
  19. ;     Close tab, window     - W, R
  20. ;     Next, previous tab    - Tab, Q
  21. ;     Undo, redo            - , and .
  22. ;  
  23.  
  24. ; This script is mostly assembled from modified versions of the following awesome scripts:
  25. ;
  26. ; # Home Row Computing by Gustavo Duarte: http://duartes.org/gustavo/blog/post/home-row-computing for
  27. ; Changes
  28.  
  29. ; Menu for caseChange below
  30. Menu, caseChange, Add, &camelCase, caseC
  31. Menu, caseChange, Add, &lower case, caseL
  32. Menu, caseChange, Add, &Paragraph, caseP
  33. Menu, caseChange, Add, &Title Case, caseT
  34. Menu, caseChange, Add, &UPPER CASE, caseU
  35. Menu, caseChange, Add
  36. Menu, caseChange, Add, C&ancel, Cancel
  37. return
  38.  
  39. ; #1: Stay off unless activated with Win+Caps
  40. #CapsLock::SetCapsLockState, % GetKeyState("CapsLock", "T") ? "AlwaysOff" : "On"
  41.  
  42.  
  43. ; #2: ShareX commands
  44. Capslock & s::SendInput !{F1}
  45. return
  46. Capslock & e::SendInput !{F2}
  47. return
  48. Capslock & o::SendInput !{F3}
  49. return
  50. Capslock & r::SendInput !{F5}
  51. return
  52. ;Capslock & p::SendInput #+c
  53. ;return
  54. ; #3: Searching online
  55. CapsLock & g::Run, % "https://www.google.com/search?q=" clip(1)
  56. return
  57. CapsLock & d::Run, % "https://www.google.com/search?q=define+" clip(1)
  58. return
  59. CapsLock & t::Run, % "https://www.thesaurus.com/browse/" clip(1)
  60. return
  61. ;CapsLock & ?::Run, % "https://www.theidioms.com/?s=" clip(1)
  62. ;return
  63. ;CapsLock & ?::Run, % "http://www.quotationspage.com/search.php?homesearch=" clip(1)
  64. ;return
  65. ;CapsLock & ?::Run, % "https://www.phrases.com/psearch/" clip(1)
  66. ;return
  67.  
  68. ; #5: Case Changer
  69. ^CapsLock::Menu, caseChange, Show
  70. return
  71.  
  72. ; #6: Line editing
  73. Capslock & a::Send, {Home 2}+{End}
  74. Capslock & x::Send, {Home 2}+{End}^x
  75. Capslock & c::Send, {Home}{End}+!{5}
  76. return
  77.  
  78. ; #7: Markdown
  79. Capslock & /::wrap("```````n", "`n```````n`n")
  80. Capslock & k::
  81.     Gui, New, +AlwaysOnTop -SysMenu, Add a link
  82.     Gui, Add, Edit, VmdTxt w300, Title of link (optional)
  83.     Gui, Add, Edit, VmdUri w300, % (Clipboard ~= "^(ftp|https?|mailto):" ? Clipboard : "Paste or type a link")
  84.     Gui, Add, Button, Default x-100 y-100 -Tabstop, OK
  85.     Gui, Show
  86. return
  87.  
  88. ; #8: Text wrap
  89. CapsLock & h::wrap("<kbd>", "</kbd>")
  90. ; CapsLock & z::wrap("~~~~")
  91. CapsLock & b::wrap("**")
  92. CapsLock & i::wrap("*")
  93. CapsLock & ,::wrap("<", ">")
  94. CapsLock & [::wrap("[[", "]]")
  95. CapsLock & ]::wrap("{{", "}}")
  96. CapsLock & 9::wrap("(", ")")
  97. CapsLock & `::wrap("``", "``")
  98. CapsLock & '::wrap(Chr(34))
  99. CapsLock & -::Send, % "{Home 2}-" A_Space
  100.  
  101. clip(copy = 0, reset = -1)
  102. {
  103.     static backup := ""
  104.     if (copy)
  105.     {
  106.         backup := ClipboardAll
  107.         Clipboard := ""
  108.         if (copy = 1)
  109.         {
  110.             Send, ^c
  111.         }
  112.         else
  113.         {
  114.             Clipboard := copy
  115.         }
  116.         ClipWait, 1
  117.         if (ErrorLevel)
  118.         {
  119.             MsgBox, 0x10,, Error getting Clipboard data.
  120.             Exit
  121.         }
  122.         SetTimer, % A_ThisFunc, % reset
  123.         return Clipboard
  124.     }
  125.     else
  126.     {
  127.         Sleep, 500
  128.         Clipboard := backup
  129.     }
  130. }
  131.  
  132. wrap(before, after := "")
  133. {
  134.     txt := clip(1, "Off")
  135.     RegExMatch(txt, "\s+$", ews)
  136.     out := before RTrim(txt) (after ? after : before) ews
  137.     Clipboard := ""
  138.     Clipboard := out
  139.     ClipWait
  140.     Send, ^v
  141.     clip()
  142. }
  143.  
  144. formatLink(txt, uri)
  145. {
  146.     static chars := StrSplit("\*_{}[]<>()#+-.!|")
  147.     ; https://www.markdownguide.org/basic-syntax#characters-you-can-escape
  148.  
  149.     if (!RegExMatch(uri, "^(ftp|https?|mailto):"))
  150.     {
  151.         return
  152.     }
  153.  
  154.     start := InStr(uri, "/",,, 3)
  155.     , txt := txt = "Title of link (optional)" ? "" : txt
  156.     , uri := SubStr(uri, 1, start) encodeURI(decodeURI(SubStr(uri, start+1)))
  157.     ; https://www.markdownguide.org/basic-syntax#link-best-practices
  158.  
  159.     if (!txt)
  160.     {
  161.         return "<" uri ">"
  162.     }
  163.     for i,chr in chars
  164.     {
  165.         txt := StrReplace(txt, chr, "\" chr)
  166.     }
  167.     return "[" txt "](" uri ")"
  168. }
  169.  
  170. encodeURI(uri, encoding := "UTF-8")
  171. {
  172.     out := ""
  173.     VarSetCapacity(var, StrLen(uri) * 2, 0)
  174.     StrPut(uri, &var, encoding)
  175.     while (code := NumGet(var, A_Index - 1, "UChar"))
  176.     {
  177.         char := Chr(code)
  178.         out .= (char ~= "[!#$&-;=?-Z_a-z~]" ? char : Format("%{:02X}", code))
  179.     }
  180.     return out
  181. }
  182.  
  183. decodeURI(uri, encoding := "UTF-8")
  184. {
  185.     while RegExMatch(uri, "i)(%[\dA-F]{2})+", code)
  186.     {
  187.         VarSetCapacity(var, 2, 0)
  188.         loop, parse, % SubStr(code, 2), `%
  189.         {
  190.             NumPut("0x" A_LoopField, var, A_Index-1, "UChar")
  191.         }
  192.         uri := StrReplace(uri, code, StrGet(&var, encoding))
  193.     }
  194.     return uri
  195. }
  196.  
  197. ButtonOK:
  198.    Gui, Submit
  199.     if (link := formatLink(mdTxt, mdUri))
  200.     {
  201.         clip(link)
  202.         Send, ^v
  203.     }
  204. GuiEscape:
  205.     Gui, Destroy
  206. return
  207.  
  208. caseC:
  209. caseL:
  210. caseP:
  211. caseT:
  212. caseU:
  213.    txt := clip(1, "Off")
  214.     switch mode := SubStr(A_ThisLabel, 0)
  215.     {
  216.         case "C": txt := RegExReplace(txt, "(([A-Z]+)|(?i)((?<=[a-z])|[a-z])([a-z]*))[ _-]([a-z]|[A-Z]+)", "$L2$L3$4$T5")
  217.         case "P": txt := RegExReplace(txt, "(\w)([^?.:!]*)", "$U1$L2")
  218.         Default: txt := Format("{:" mode "}", txt)
  219.     }
  220.     Clipboard := txt
  221.     Send, ^v
  222.     clip()
  223. Cancel:
  224. return
  225.  
  226.  
  227. ; #10 Paste w/o formatting
  228. CapsLock & v::
  229. ; Trim leading/trailing white space from empty lines
  230. Clipboard:=RegExReplace(Clipboard,"m)^[ \t]*$","`r`n")
  231. ; copied from http://ahkscript.org/docs/commands/StringReplace.htm
  232. ; Remove all blank lines from the text in a variable:
  233. Loop
  234. {
  235.     StringReplace, ClipBoard, ClipBoard, `r`n`r`n, --[ahkparagraphmarker]--, UseErrorLevel
  236.     if ErrorLevel = 0  ; No more replacements needed.
  237.     break
  238. }
  239. ;Replace all new lines with a space topreventjoinedwords
  240. StringReplace, ClipBoard, ClipBoard, `r`n, %A_Space%, All
  241. ; Remove all double spaces (useful for justified text)
  242. Loop
  243. {
  244.     StringReplace, ClipBoard, ClipBoard, %A_Space%%A_Space%, %A_Space%, UseErrorLevel
  245.     if ErrorLevel = 0  ; No more replacements needed.
  246.         break
  247. }
  248. ; re-create paragraphs again
  249. StringReplace, ClipBoard, ClipBoard,--[ahkparagraphmarker]--,`r`n`r`n, All
  250. ; remove any leftover remaining leading spaces
  251. Clipboard:=RegExReplace(Clipboard,"m)^[ \t]*")
  252. Send ^v
  253. Return
  254.  
  255.  
  256. ; #10: Non-Caps Replacements and Hotstrings
  257. !-::Send,; Alt+Minus = Em dash
  258. +!-::Send,; Shift+Alt+Minus = En dash
  259.  
  260. ::|c::©
  261. ::(c)::©
  262.  
  263. ::|r::®
  264. ::(r)::®
  265.  
  266. ::|s::§
  267. ::(tm)::™
  268.  
  269. :c:|o::•
  270. ::|bull::•
  271. ::|bullet::•
  272.  
  273. ; Arrows
  274. :?*:-->::→
  275. :?*:<--::←
  276. :?*:<->::↔
  277. ::|^::↑
  278. ::|v::↓
  279.  
  280. ; ------- SET REPLACEMENTS -----------
  281.  
  282. :?:]d::  ; This hotstring replaces "]d" with the current date and time via the commands below.
  283. FormatTime, CurrentDateTime,, yyyy-MM-dd HH:mm  ; It will look like 2005-09-01 15:53
  284. SendInput %CurrentDateTime%
  285. return
  286.  
  287.  
  288.  
  289.  
  290. ;------------------------------------------------------------------------------
  291. ;💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀 GRAVEYARD 💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀
  292. ;------------------------------------------------------------------------------
  293.  
  294. ; #4: Launching apps: replaced by Winkey + number to run from taskbar
  295. ;CapsLock & v::Run, % A_AppData "\..\Local\Vivaldi\Application\vivaldi.exe"
  296. ;CapsLock & n::Run, % A_AppData "\..\Local\Obsidian\Obsidian.exe"
  297. ;CapsLock & m::Run, % ProgramFilesx86 "\eM Client\MailClient.exe"
  298.  
  299.  
  300. ; ---------------- Hotstring Helper ------------------------------
  301. ; Andreas Borutta suggested the following script, which might be useful if you are a heavy user of hotstrings. By pressing Win+H (or another hotkey of your choice), the currently selected text can be turned into a hotstring. For example, if you have "by the way" selected in a word processor, pressing Win+H will prompt you for its abbreviation (e.g. btw) and then add the new hotstring to the script. It will then reload the script to activate the hotstring.
  302.  
  303. ; Note: The Hotstring function can be used to create new hotstrings without reloading. Take a look at the first example in the example section of the function's page to see how this could be done.
  304.  
  305. #h::  ; Win+H hotkey
  306. ; Get the text currently selected. The clipboard is used instead of
  307. ; "ControlGet Selected" because it works in a greater variety of editors
  308. ; (namely word processors).  Save the current clipboard contents to be
  309. ; restored later. Although this handles only plain text, it seems better
  310. ; than nothing:
  311. AutoTrim Off  ; Retain any leading and trailing whitespace on the clipboard.
  312. ClipboardOld := ClipboardAll
  313. Clipboard := ""  ; Must start off blank for detection to work.
  314. Send ^c
  315. ClipWait 1
  316. if ErrorLevel  ; ClipWait timed out.
  317.     return
  318. ; Replace CRLF and/or LF with `n for use in a "send-raw" hotstring:
  319. ; The same is done for any other characters that might otherwise
  320. ; be a problem in raw mode:
  321. StringReplace, Hotstring, Clipboard, ``, ````, All  ; Do this replacement first to avoid interfering with the others below.
  322. StringReplace, Hotstring, Hotstring, `r`n, ``r, All  ; Using `r works better than `n in MS Word, etc.
  323. StringReplace, Hotstring, Hotstring, `n, ``r, All
  324. StringReplace, Hotstring, Hotstring, %A_Tab%, ``t, All
  325. StringReplace, Hotstring, Hotstring, `;, ```;, All
  326. Clipboard := ClipboardOld  ; Restore previous contents of clipboard.
  327. ; This will move the InputBox's caret to a more friendly position:
  328. SetTimer, MoveCaret, 10
  329. ; Show the InputBox, providing the default hotstring:
  330. 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%
  331. if ErrorLevel  ; The user pressed Cancel.
  332.     return
  333. if InStr(Hotstring, ":R`:::")
  334. {
  335.     MsgBox You didn't provide an abbreviation. The hotstring has not been added.
  336.     return
  337. }
  338. ; Otherwise, add the hotstring and reload the script:
  339. FileAppend, `n%Hotstring%, %A_ScriptFullPath%  ; Put a `n at the beginning in case file lacks a blank line at its end.
  340. Reload
  341. Sleep 200 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
  342. 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.
  343. IfMsgBox, Yes, Edit
  344. return
  345.  
  346. MoveCaret:
  347. IfWinNotActive, New Hotstring
  348.     return
  349. ; Otherwise, move the InputBox's insertion point to where the user will type the abbreviation.
  350. Send {Home}{Right 3}
  351. SetTimer, MoveCaret, Off
  352. return
  353.  
  354. ;
  355. ; Start of auto-generated content by Hotstring Helper
  356. ;
  357.  
  358. ;(removed for privacy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement