Guest User

Untitled

a guest
Mar 10th, 2023
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.60 KB | None | 0 0
  1. /* (!)(A) ctrl capslock MENU.ahk */
  2.  
  3.  
  4. ;\/\/\/\/\/\/
  5. ;CTRL+CAPSLOCK to activate the menu
  6. ;
  7. ;CTRL+SHIFT+CAPSLOCK to send Ctrl A before activating the menu, to select all text first.
  8. ;/\/\/\/\/\/\/\
  9.  
  10.  
  11. /*
  12.  
  13. ===SETTINGS===
  14.  
  15. Dark mode on by default:
  16. - Ctrl F this: MenuDark(Dark:=4)
  17. - Change the 4 to a 2
  18. - (The other numbers dont do anything different)
  19.  
  20. */
  21.  
  22.  
  23.  
  24.  
  25. /*
  26. README:
  27.  
  28. This is my first time making a script like this. I dont want to admit how much time I put into this, but lets just say it was a lot.
  29. Most of the code here is copy and pasted from other sources, I mainly just fit everyting together.
  30. I wasnt the one who made the lego bricks, but I was the one who jammed them all together, even when they didnt really feel like they would fit.
  31. ...which is why some things might seem a little scattered and unorginized - (I am not a coder)
  32.  
  33. =
  34. I was inspired to make this after using u/S3rLoG's capslock menu. It was really good.
  35. But his first script had this AWESOME loading bar GUI but he ended up removing it in later versions. ██████████████]99%
  36. I understand why he removed it (it was useless), but the loading bar gui had so much personality, idk why but I really missed it when it was removed.
  37. So that is why Ive decided to keep it alive through an easter egg in the menu.........
  38. =
  39.  
  40. BTW if youre into this kind of thing, definitely check out u/S3rLoG's current script. Its jampacked with a lot of cool features! -> (https://www.reddit.com/r/AutoHotkey/comments/m0ijbo/capslock_menu/)
  41. However, my goal with this was to make a more precise menu, only including things that I think are necessary/close to the necessary side of the spectrum.
  42.  
  43.  
  44. Feel free to move around the options or add your own options, its actually extremely simple..........
  45.  
  46.  
  47.  
  48.  
  49. =================================(Read below for instructions on how to add your own buttons to this script)=================================
  50.  
  51. __WARNING: (Adding your own options)__
  52. IF YOU WANT TO ADD YOUR OWN, TempText is really hard to understand, but you DONT have to use TempText. (I wouldnt recommend using it either)
  53. You can simply have it send ^c, and then put the changed text in the clipboard, and send ^v (optional: save the clipboard before, then set the clipboard back to what it previously was after)
  54. ██ Just make sure to put 'Exit' at the end of any new options you add (if you dont use TempText) so it wont paste the TempText afterwards (put Exit, not ExitApp, as that quits the whole script)
  55.  
  56.  
  57.  
  58.  
  59.  
  60. __EXAMPLE: (Adding your own options)__
  61.  
  62. THIS:
  63.  
  64. Case "&UPPERCASE":
  65. StringUpper, TempText, TempText
  66.  
  67.  
  68. CAN ALSO BE WRITTEN AS:
  69.  
  70.  
  71. Case "&UPPERCASE":
  72. ClipSaved := ClipboardAll ;save whats currently copied
  73.  
  74. Send, ^c
  75. stringUpper, clipboard, clipboard ;makes clipboard uppercase somehow (use google for this part)
  76. sleep 100
  77. Send ^v ;paste output
  78.  
  79. clipboard := ClipSaved ;set clipboard back to what it was originally
  80.  
  81. Exit ;Exit so it doesnt continue, and go to the function that pastes TempText
  82. return
  83.  
  84.  
  85.  
  86.  
  87. Both of these options are interchangable
  88.  
  89.  
  90. Ctrl F this: THE REAL STUFF
  91. This is where all the cases are.
  92. */
  93.  
  94.  
  95. ;;;;;;; DARK MODE ;;;;;;; Change the values below to change the color of the menu.
  96.  
  97.  
  98. DarkMode := false ; set initial mode to light
  99.  
  100.  
  101.  
  102. MenuDark()
  103.  
  104. ; 0=Default 1=AllowDark 2=ForceDark 3=ForceLight 4=Max
  105.  
  106. MenuDark(Dark:=4) { ;<=--------------------------------------------------------------<=PERMINANTLY CHANGE TO DARK MODE (make it the default)
  107. ;https://stackoverflow.com/a/58547831/894589
  108. static uxtheme := DllCall("GetModuleHandle", "str", "uxtheme", "ptr")
  109. static SetPreferredAppMode := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 135, "ptr")
  110. static FlushMenuThemes := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 136, "ptr")
  111.  
  112. DllCall(SetPreferredAppMode, "int", Dark) ; 0=Default 1=AllowDark 2=ForceDark 3=ForceLight 4=Max
  113. DllCall(FlushMenuThemes)
  114. }
  115.  
  116.  
  117. #NoEnv
  118. SendMode Input
  119. SetWorkingDir %A_ScriptDir%
  120. #SingleInstance Force
  121. SetTitleMatchMode 2
  122. SetBatchLines -1 ; Run the script at maximum speed
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. GroupAdd All
  131.  
  132. Menu Case, Add, &1 UPPERCASE, CCase ; '&' symbol makes pressing U activate this option
  133. Menu Case, Add, &2 lowercase, CCase
  134. Menu Case, Add, &3 Title Case, CCase
  135. Menu Case, Add, &4 Sentence case, CCase
  136. Menu Case, Add
  137. Menu Case, Add, ″...″ &Q, CCase
  138. Menu Case, Add, '...' &W, CCase
  139. Menu Case, Add, (...) &E, CCase
  140. Menu Case, Add
  141.  
  142. ;
  143.  
  144. Menu More, Add, `{...} &A, CCase
  145. Menu More, Add, `*...* &S, CCase
  146. Menu More, Add
  147. Menu More, Add, &Date - 06/07/04, CCase
  148. Menu More, Add
  149. Menu More, Add, iNVERT cASE, CCase
  150. Menu More, Add, SpOnGeBoB cAsE, CCase
  151. Menu More, Add, S p r e a d T e x t, CCase
  152. Menu More, Add, raNDoM cASE, CCase
  153. Menu More, Add, Reverse, CCase
  154. Menu More, Add
  155. Menu More, Add, Dark Mode | Light Mode, CCase
  156.  
  157.  
  158. Menu Case, Add, &A - More Options, :More
  159.  
  160.  
  161. ;
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. ^CapsLock:: ;<=---------------------------------------MAIN SHORTCUT HERE (ctrl capslock)
  171. GetText(TempText)
  172. Menu Case, Show ;<=----------------------------------Show capslock menu
  173. Return
  174.  
  175.  
  176.  
  177.  
  178. ^+capslock::
  179. sleep 100
  180. send ^a ;<=-------send ^a,
  181. sleep 200
  182. GetText(TempText)
  183. Menu Case, Show ;<=-------Then show capslock menu
  184. return
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192. /*
  193. If (fCtrl2) {
  194. sleep 100
  195. send ^a
  196. sleep 300
  197. }
  198. */
  199.  
  200.  
  201. ;;;If ERRORLEVEL { ;<=---IF NO TEXT IS SELECTED,
  202. ;;;If NOT ERRORLEVEL ;IF TEXT IS SELECTED,
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211. ;btw TempText is just whats been selected/copied
  212. ;Exit
  213. ;Exit to exit
  214.  
  215.  
  216.  
  217.  
  218. CopyClipboard()
  219. {
  220. global ClipSaved := ""
  221. ClipSaved := ClipboardAll ; save original clipboard contents
  222. Clipboard := "" ; start off empty to allow ClipWait to detect when the text has arrived
  223. Send {Ctrl down}c{Ctrl up}
  224. Sleep 150
  225. ClipWait, 1.5, 1
  226. if ErrorLevel
  227. {
  228. MsgBox, 262208, AutoHotkey, Copy to clipboard failed.
  229. Clipboard := ClipSaved ; restore the original clipboard contents
  230. ClipSaved := "" ; clear the variable
  231. return
  232. }
  233. }
  234.  
  235.  
  236.  
  237. CopyClipboardCLM()
  238. {
  239. global ClipSaved
  240. WinGet, id, ID, A
  241. WinGetClass, class, ahk_id %id%
  242. if (class ~= "(Cabinet|Explore)WClass|Progman")
  243. Send {F2}
  244. Sleep 100
  245. CopyClipboard()
  246. if (ClipSaved != "")
  247. Clipboard := Clipboard
  248. else
  249. Exit
  250. }
  251.  
  252. PasteClipboardCLM()
  253. {
  254. global ClipSaved
  255. WinGet, id, ID, A
  256. WinGetClass, class, ahk_id %id%
  257. if (class ~= "(Cabinet|Explore)WClass|Progman")
  258. Send {F2}
  259. Send ^v
  260. Sleep 100
  261. Clipboard := ClipSaved
  262. ClipSaved := ""
  263. Exit
  264. }
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. ;;;;;;;;;;;;;;;;;; THE STUFF ;;;;;;;;;;;;;;;;;;;
  272.  
  273. CCase:
  274. Switch A_ThisMenuItem {
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281. ;;;;;; THE REAL STUFF ;;;;;; ===============================================================================================================================================================================================================================================
  282.  
  283.  
  284. Case "&1 UPPERCASE":
  285. StringUpper, TempText, TempText
  286.  
  287. Case "&2 lowercase":
  288. StringLower, TempText, TempText
  289.  
  290. Case "&3 Title Case":
  291. StringLower, TempText, TempText, T
  292.  
  293. Case "&4 Sentence case":
  294. StringLower, TempText, TempText
  295. TempText := RegExReplace(TempText, "((?:^|[.!?]\s+)[a-z])", "$u1")
  296.  
  297.  
  298. ;__________________________________________________________________________________________________
  299.  
  300. Case "″...″ &Q":
  301. TempText := RegExReplace(TempText, "\s+$") ;gets rid of whitespace at end (ChatGPT)
  302. TempText := """" TempText """"
  303.  
  304. Case "'...' &W":
  305. TempText := RegExReplace(TempText, "\s+$")
  306. TempText := "'" TempText "'"
  307.  
  308. Case "(...) &E":
  309. TempText := RegExReplace(TempText, "\s+$")
  310. TempText := "(" TempText ")"
  311.  
  312. ;-----More Options--------------------------
  313.  
  314. Case "`{...} &A":
  315. TempText := RegExReplace(TempText, "\s+$")
  316. TempText := "{" TempText "}"
  317.  
  318. Case "`*...* &S":
  319. TempText := RegExReplace(TempText, "\s+$")
  320. TempText := "*" TempText "*"
  321.  
  322. ;-------------
  323.  
  324. Case "&Date - 06/07/04":
  325. FormatTime, CurrentDateTime,,MM/dd/yy ; - hh:mmtt
  326. SendInput %CurrentDateTime%
  327. exit
  328.  
  329.  
  330. ;MORE__________________________________________________________________________________________________
  331.  
  332.  
  333.  
  334. Case "iNVERT cASE":
  335. {
  336. CopyClipboardCLM()
  337. Inv_Char_Out := ""
  338. Loop % StrLen(Clipboard)
  339. {
  340. Inv_Char := SubStr(Clipboard, A_Index, 1)
  341. if Inv_Char is Upper
  342. Inv_Char_Out := Inv_Char_Out Chr(Asc(Inv_Char) + 32)
  343. else if Inv_Char is Lower
  344. Inv_Char_Out := Inv_Char_Out Chr(Asc(Inv_Char) - 32)
  345. else
  346. Inv_Char_Out := Inv_Char_Out Inv_Char
  347. }
  348. Clipboard := Inv_Char_Out
  349. PasteClipboardCLM()
  350. }
  351.  
  352. Case "SpOnGeBoB cAsE":
  353. {
  354. CopyClipboardCLM()
  355. Inv_Char_Out := ""
  356. StringLower, Clipboard, Clipboard
  357. Loop, Parse, Clipboard
  358. {
  359. if (Mod(A_Index, 2) = 0)
  360. Inv_Char_Out .= Format("{1:L}", A_LoopField)
  361. else
  362. Inv_Char_Out .= Format("{1:U}", A_LoopField)
  363. }
  364. Clipboard := Inv_Char_Out
  365. PasteClipboardCLM()
  366. }
  367.  
  368.  
  369. Case "S p r e a d T e x t":
  370. {
  371. vText := "exemple"
  372. TempText := % RegExReplace(TempText, "(?<=.)(?=.)", " ")
  373. }
  374.  
  375.  
  376. Case "raNDoM cASE":
  377. {
  378. CopyClipboardCLM()
  379. RandomCase := ""
  380. for _, v in StrSplit(Clipboard)
  381. {
  382. Random, r, 0, 1
  383. RandomCase .= Format("{:" (r?"L":"U") "}", v)
  384. }
  385. Clipboard := RandomCase
  386. PasteClipboardCLM()
  387. }
  388.  
  389.  
  390. Case "Reverse":
  391. Temp2 =
  392. StringReplace, TempText, TempText, `r`n, % Chr(29), All
  393. Loop Parse, TempText
  394. Temp2 := A_LoopField . Temp2
  395. StringReplace, TempText, Temp2, % Chr(29), `r`n, All
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404. Case "Dark Mode | Light Mode":
  405.  
  406. If (DarkMode)
  407. {
  408. DarkMode := false
  409. ;Menu, Case, Toggle Mode, Dark Mode
  410. MenuDark(3) ; Set to ForceLight
  411. WelcomeTrayTipLight()
  412. }
  413. else
  414. {
  415. DarkMode := true
  416. ;Menu, Case, Toggle Mode, Light Mode
  417. MenuDark(2) ; Set to ForceDark
  418. WelcomeTrayTipDark()
  419. }
  420. Return
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427. }
  428.  
  429. SetCapsLockState, Off
  430.  
  431.  
  432.  
  433.  
  434.  
  435. ;__________________________________________________________________________________________________
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442. ;;;;;;;;;;;\/ THIS HAS TO BE AT THE BOTTOM OF ALL THE CASE THINGS ;;;;;;;;;;;;;
  443.  
  444. PutText(TempText)
  445. SetCapsLockState, Off
  446. Return
  447.  
  448. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457. ;;;;;;;;;;;;;;;;;;; Handy function. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  458. ; Copies the selected text to a variable while preserving the clipboard.
  459. GetText(ByRef MyText = "")
  460. {
  461. SavedClip := ClipboardAll
  462. Clipboard =
  463. Send ^c
  464. ClipWait 0.5
  465. If ERRORLEVEL
  466. {
  467. Clipboard := SavedClip
  468. MyText =
  469. Return
  470. }
  471. MyText := Clipboard
  472. Clipboard := SavedClip
  473. Return MyText
  474. SetCapsLockState, Off
  475. }
  476.  
  477. ; Pastes text from a variable while preserving the clipboard.
  478. PutText(MyText)
  479. {
  480. SavedClip := ClipboardAll
  481. Clipboard = ; For better compatability
  482. Sleep 20 ; with Clipboard History
  483. Clipboard := MyText
  484. Send ^v
  485. Sleep 100
  486. Clipboard := SavedClip
  487. SetCapsLockState, Off
  488. Return
  489. }
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496. SetCapsLockState, Off
  497. Send, {capslock up}
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522. ;;;;;;;;;;;;;;;;;;;; Dark Mode Activated GUI Script ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  523.  
  524.  
  525.  
  526.  
  527. WelcomeTrayTipDark() {
  528. static GuiCreated := 0
  529. static HwndWelcomeScreen1
  530. static MonRight, MonBottom
  531. if !GuiCreated {
  532. GuiCreated := 1
  533. Gui, WelcomeScreen1:New, +AlwaysOnTop -Caption +ToolWindow +HwndHwndWelcomeScreen1 +LastFound -DPIScale +E0x20 ; Clickthrough=E0x20
  534. Gui, WelcomeScreen1:Margin, 30, 25
  535. Gui, WelcomeScreen1:Font, s30, Segoe UI
  536. Gui, WelcomeScreen1:Color, 1A1A1A
  537. Gui, WelcomeScreen1:Add, Text, y20 cWhite, Dark Mode Activated ;, %A_UserName% ; make a text control showing welcome back, (username)
  538. WinSet, Transparent, 0 ; set gui transparent
  539. SysGet, P, MonitorPrimary ; get primary monitor number
  540. SysGet, Mon, MonitorWorkArea, % P ; get size of primary monitor
  541. Gui, WelcomeScreen1:Show, Hide ; Show gui
  542. WinGetPos, X, Y, W, H ; get pos of gui
  543. WinMove, % MonRight - W - 10, % MonBottom - H - 10 ; move gui to bottom right
  544. WinSet, Region, 0-0 W%W% H%H% R20-20 ; round corners
  545. }
  546. Gui, WelcomeScreen1:Show, NA
  547. bf := Func("AnimateFadeIn").Bind(HwndWelcomeScreen1)
  548. SetTimer, %bf%, -200
  549. }
  550.  
  551.  
  552. WelcomeTrayTipLight() {
  553. static GuiCreated := 0
  554. static HwndWelcomeScreen
  555. static MonRight, MonBottom
  556. if !GuiCreated {
  557. GuiCreated := 1
  558. Gui, WelcomeScreen:New, +AlwaysOnTop -Caption +ToolWindow +HwndHwndWelcomeScreen +LastFound -DPIScale +E0x20 ; Clickthrough=E0x20
  559. Gui, WelcomeScreen:Margin, 30, 25
  560. Gui, WelcomeScreen:Font, s30, Segoe UI
  561. Gui, WelcomeScreen:Color, white ;<=--\/---------------COLOR OF BOX / TEXT
  562. Gui, WelcomeScreen:Add, Text, y20 cBlack, Light Mode Activated ;, %A_UserName% ; make a text control showing welcome back, (username)
  563. WinSet, Transparent, 0 ; set gui transparent
  564. SysGet, P, MonitorPrimary ; get primary monitor number
  565. SysGet, Mon, MonitorWorkArea, % P ; get size of primary monitor
  566. Gui, WelcomeScreen:Show, Hide ; Show gui
  567. WinGetPos, X, Y, W, H ; get pos of gui
  568. WinMove, % MonRight - W - 10, % MonBottom - H - 10 ; move gui to bottom right
  569. WinSet, Region, 0-0 W%W% H%H% R20-20 ; round corners
  570. }
  571. Gui, WelcomeScreen:Show, NA
  572. bf := Func("AnimateFadeIn").Bind(HwndWelcomeScreen)
  573. SetTimer, %bf%, -200
  574. }
  575.  
  576.  
  577.  
  578. AnimateFadeIn(hwnd) {
  579. static Value := 0
  580. WinSet, Transparent, % Value+=15, % "ahk_id" hwnd
  581. if (Value >= 255) { ; if gui is fully opaque
  582. Value := 0 ; reset transparency value
  583. bf := Func("AnimateFadeOut").Bind(hwnd) ; make bound function to fade out
  584. SetTimer, %bf%, -1000 ;<=--------------------------------------------------------CHANGE HOW LONG
  585. } else {
  586. bf := Func("AnimateFadeIn").Bind(hwnd) ; create bound functiion to fade in
  587. SetTimer, %bf%, -15 ; rerun bound function until gui is fully opaque
  588. }
  589. }
  590.  
  591. AnimateFadeOut(hwnd) {
  592. static Value := 255
  593. WinSet, Transparent, % Value-=15, % "ahk_id" hwnd
  594. if (Value <= 0) { ; if gui invisible
  595. Value := 255 ; reset transparency value
  596. Gui, %hwnd%:Hide ; hide gui when finished
  597. } else {
  598. bf := Func("AnimateFadeOut").Bind(hwnd) ; create bound functiion to fade out
  599. SetTimer, %bf%, -15 ; rerun bound function until gui is transparent
  600. }
  601. }
  602.  
  603.  
  604.  
  605.  
Advertisement
Add Comment
Please, Sign In to add comment