Advertisement
Yunga

AutoHotKey

Jun 21st, 2013
1,935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ------------------------------------------------------------------------------
  2. ; http://L.AutoHotKey.net/ (v1.1.09.04) -- yunga.palatino@gmail.com
  3. ; ------------------------------------------------------------------------------
  4. ; See http://www.autohotkey.com/docs/scripts/
  5.  
  6. ; ----- Directives:
  7. #NoEnv
  8. #MaxThreadsPerHotkey 2
  9. #MaxHotkeysPerInterval 100                          ; Avoid when mouse wheel turned very fast
  10. #Hotstring EndChars -()[]{}:;'"/\,.?!`n `t
  11.  
  12. ; ----- GlobalVars
  13. EnvGet, HomeDir, USERPROFILE
  14.  
  15. AutoFireClickToggle = 0
  16.  
  17. ; Windows Resizing Vars
  18. A_ScreenChatWidth     := 512                        ; Change this
  19. A_ScreenWorkWidth     := A_ScreenWidth - A_ScreenChatWidth
  20. A_ScreenHalfWidth     := Round( A_ScreenWidth / 2 )
  21. A_ScreenHalfHeight    := Round(A_ScreenHeight / 2 )
  22. A_ScreenThirdWidth    := Round( A_ScreenWidth / 3 )
  23. A_ScreenTwoThirdWidth := 2 * A_ScreenThirdWidth
  24. ; #!m::MsgBox %A_ScreenWidth%x%A_ScreenHeight%`n%A_ScreenHalfWidth%x%A_ScreenHalfHeight%`n%A_ScreenWorkWidth%-%A_ScreenChatWidth%`nA_ScreenThirdWidth
  25.  
  26. ; Scroll Whell Vars
  27. MinLinesPerNotch := 1
  28. MaxLinesPerNotch := 5
  29. AccelerationThreshold := 100
  30. AccelerationType := "L" ;Change to "P" for parabolic acceleration
  31. StutterThreshold := 10
  32.  
  33.  
  34. ; ----- End of Init:
  35. Return
  36.  
  37. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  38. ; ----- Ctrl-Alt-Win-R Reload the current AutoHotKey script
  39. ^#!r::
  40.     SplashTextOn, , , Reloading....
  41.     Reload
  42.     Sleep 1000 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
  43.     SplashTextOff
  44.     MsgBox, 4,, The script could not be reloaded. Would you like to open it for editing?
  45.     IfMsgBox, Yes, Edit
  46. Return
  47.  
  48. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  49. ; ----- Launchers Hot Keys:
  50.  
  51. ; Launchy is on #^Space
  52. #c::Run,            C:\Windows\system32\calc.exe                                            ; Calculator
  53. #+c::Run,           C:\Program Files\Ditto\Ditto.exe                                        ; Clipboard tool
  54. #e::Run             C:\Windows\Explorer.exe D:\                                             ; Explorer
  55. #+e::Run,           C:\Prg\Far\Far.exe                                                      ; Explorer
  56. #f::Run,            C:\Program Files\Everything\Everything.exe                              ; Find
  57. #+f::Run,           C:\Program Files (x86)\FileZilla\Client\filezilla.exe                   ; FTP
  58. #m::Run             C:\Program Files\VideoLAN\VLC\vlc.exe                                   ; Media
  59. #+m::Run            C:\Program Files (x86)\Winamp                                           ; Media
  60. #o::Run,            C:\Program Files\Microsoft Office\Office15\WINWORD.EXE                  ; Office
  61. #+o::Run,           C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe              ; Office - mails
  62. #+r::Run,            C:\Program Files (x86)\PuTTY\putty.exe                                  ; Remote shell
  63. #^r::Run,           C:\Program Files (x86)\TeamViewer\Version8\TeamViewer.exe               ; Remote desktop
  64. #s::Run,            C:\prg\cygwin\bin\mintty.exe -e screen -ln -D -RR , %HomeDir%           ; bash Shell
  65. #+s::Run,           C:\Prg\4Dos\tcc.exe  , %HomeDir%                                        ; 4dos Shell
  66. #^s::Run,           C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe , %HomeDir%   ; powerShell
  67. #^!s::Run,          C:\Program Files (x86)\Git\bin\sh.exe --login -i                        ; git Shell
  68. #t::Run,            C:\Program Files (x86)\Notepad++\notepad++.exe                          ; Text editor
  69. #+t::Run,           C:\Program Files\Sublime Text 3\sublime_text.exe                        ; Text editor
  70. #^t::Run,           C:\Program Files\KDiff3\kdiff3.exe                                      ; Text diff
  71. #w::Run,            C:\Program Files (x86)\Google\Chrome\Application\chrome.exe             ; Web browser
  72. #+w::Run,           C:\Program Files (x86)\Mozilla Firefox\firefox.exe                      ; Web browser
  73. #^w::Run,           C:\Program Files (x86)\Opera\launcher.exe                               ; Web browser
  74. #Break::Run,        C:\Program Files\ProcessHacker\ProcessHacker.exe                        ; TaskManager
  75. #+Break::Run,       C:\Prg\OllyDbg\ollydbg.exe                                              ; Debugger
  76. #PrintScreen::Run,  C:\Program Files\Greenshot\Greenshot.exe                                ; Screenshots
  77. #+PrintScreen::Run, C:\Program Files (x86)\ABBYY FineReader 11\Bonus.ScreenshotReader.exe   ; Screenshots reader
  78.  
  79. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  80. ; ----- Abbrevs
  81. ::btw::by the way                       ; btw: Abbrev Example
  82. :O:@yunga::yunga.palatino@gmail.com
  83. :O:@date::
  84.     FormatTime, CurrentDateTime,, yyyyMMdd
  85.     SendInput %CurrentDateTime%
  86. Return
  87. :O:@time::
  88.     FormatTime, CurrentDateTime,, HHmmss
  89.     SendInput %CurrentDateTime%
  90. Return
  91. :O:@ts::
  92.     FormatTime, CurrentDateTime,, yyyyMMdd_HHmmss
  93.     SendInput %CurrentDateTime%
  94. Return
  95.  
  96.  
  97. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  98. ; ----- Win(-Shift)-F1 for Auto-Fire for clicks (1/10sec delay, shift for 1 second delay)
  99.  
  100. #F1::
  101.     AutoFireClickToggle := !AutoFireClickToggle
  102.     While AutoFireClickToggle {
  103.         Click
  104.         Sleep 100
  105.     }
  106. Return
  107.  
  108. #+F1::
  109.     AutoFireClickToggle := !AutoFireClickToggle
  110.     While AutoFireClickToggle {
  111.         Click
  112.         Sleep 1000
  113.     }
  114. Return
  115.  
  116.  
  117. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  118. ; ----- Ctrl-Shift-c: Copy and Search Google (from AutoHotKey Examples)
  119. ^+c::
  120.     Send, ^c
  121.     Sleep 100
  122.     Run "http://www.google.com/search?q=%clipboard%"
  123. Return
  124.  
  125. ^!c::
  126.     Send, ^c
  127.     Sleep 100
  128.     Run "https://en.wikipedia.org/w/index.php?title=Special:Search&search=%clipboard%"
  129. Return
  130.  
  131.  
  132. ;^+v::
  133. ;   TempText := ClipBoard
  134. ;   If (TempText != "")
  135. ;      PutText(ClipBoard)
  136. ;Return
  137.  
  138.  
  139.  
  140. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  141. ; ----- Always on Top
  142.  
  143. #!SPACE::Winset, Alwaysontop, Toggle, A  ; Control-Space Toggle AlwaysOnTop on Active Window
  144.  
  145. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  146. ; ----- Resize Windows Function
  147. ResizeWin(Width = 0,Height = 0) {
  148.     WinGetPos,X,Y,W,H,A
  149.  
  150.     If %Width% = 0
  151.         Width := W
  152.  
  153.     If %Height% = 0
  154.         Height := H
  155.  
  156.     ; WinSet Style, -0xC00000, A             ; Remove the active window's title bar (WS_CAPTION).
  157.  
  158.     WinMove,A,,%X%,%Y%,%Width%,%Height%
  159. }
  160.  
  161. ; #!u::ResizeWin(800,600)
  162.  
  163. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  164. ; ----- Maps windows Positions on the keyboard
  165. ;    a zer t
  166. ;    q sdf g
  167. ;    w xcv b
  168.  
  169. #!a::WinMove,A,,0,0,%A_ScreenWorkWidth%,%A_ScreenHalfHeight%
  170. #!q::WinMove,A,,0,0,%A_ScreenWorkWidth%,%A_ScreenHeight%
  171. #!w::WinMove,A,,0,%A_ScreenHalfHeight%,%A_ScreenWorkWidth%,%A_ScreenHalfHeight%
  172. #!+a::WinMove,A,,0,0,%A_ScreenChatWidth%,%A_ScreenHalfHeight%
  173. #!+q::WinMove,A,,0,0,%A_ScreenChatWidth%,%A_ScreenHeight%
  174. #!+w::WinMove,A,,0,%A_ScreenHalfHeight%,%A_ScreenChatWidth%,%A_ScreenHalfHeight%
  175.  
  176. #!z::WinMove,A,,0,0,%A_ScreenHalfWidth%,%A_ScreenHalfHeight%
  177. #!e::WinMove,A,,0,0,%A_ScreenWidth%,%A_ScreenHalfHeight%
  178. #!r::WinMove,A,,%A_ScreenHalfWidth%,0,%A_ScreenHalfWidth%,%A_ScreenHalfHeight%
  179. #!+z::WinMove,A,,0,0,%A_ScreenThirdWidth%,%A_ScreenHeight%
  180. #!+e::WinMove,A,,%A_ScreenThirdWidth%,0,%A_ScreenThirdWidth%,%A_ScreenHeight%
  181. #!+r::WinMove,A,,%A_ScreenTwoThirdWidth%,0,%A_ScreenThirdWidth%,%A_ScreenHeight%
  182.  
  183. #!s::WinMove,A,,0,0,%A_ScreenHalfWidth%,%A_ScreenHeight%
  184. #!d::WinMove,A,,320,156,1280,768
  185. #!f::WinMove,A,,%A_ScreenHalfWidth%,0,%A_ScreenHalfWidth%,%A_ScreenHeight%
  186.  
  187. #!x::WinMove,A,,0,%A_ScreenHalfHeight%,%A_ScreenHalfWidth%,%A_ScreenHalfHeight%
  188. #!c::WinMove,A,,0,%A_ScreenHalfHeight%,%A_ScreenWidth%,%A_ScreenHalfHeight%
  189. #!v::WinMove,A,,%A_ScreenHalfWidth%,%A_ScreenHalfHeight%,%A_ScreenHalfWidth%,%A_ScreenHalfHeight%
  190.  
  191. #!t::WinMove,A,,%A_ScreenWorkWidth%,0,%A_ScreenChatWidth%,%A_ScreenHalfHeight%
  192. #!g::WinMove,A,,%A_ScreenWorkWidth%,0,%A_ScreenChatWidth%,%A_ScreenHeight%
  193. #!b::WinMove,A,,%A_ScreenWorkWidth%,%A_ScreenHalfHeight%,%A_ScreenChatWidth%,%A_ScreenHalfHeight%
  194. #!+t::WinMove,A,,%A_ScreenChatWidth%,0,%A_ScreenWorkWidth%,%A_ScreenHalfHeight%
  195. #!+g::WinMove,A,,%A_ScreenChatWidth%,0,%A_ScreenWorkWidth%,%A_ScreenHeight%
  196. #!+b::WinMove,A,,%A_ScreenChatWidth%,%A_ScreenHalfHeight%,%A_ScreenWorkWidth%,%A_ScreenHalfHeight%
  197.  
  198. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  199. ; ----- Move mouse with arrow keys
  200. #!Left::MouseMove, -1, 0, 0, R
  201. #!Right::MouseMove, 1, 0, 0, R
  202. #!Up::MouseMove, 0, -1, 0, R
  203. #!Down::MouseMove, 0, 1, 0, R
  204.  
  205.  
  206. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  207. ; ----- Windows Transparency
  208. ; Win-Alt       y/Y - transparency level +/-
  209. ; Win-Ctrl-Alt  y/Y - turn transparency off/60%
  210. #^!y::WinSet, Transparent, OFF, A
  211. #^!+y::WinSet, Transparent, 154, A
  212.  
  213. #!y::
  214.     WinGet Trans, Transparent, A
  215.     If Trans =
  216.         Trans := 255
  217.  
  218.     Trans := Trans - 17
  219.     If Trans < 16
  220.         Trans = 17
  221.     WinSet, Transparent, %Trans%, A
  222. Return
  223.  
  224. #!+y::
  225.     WinGet Trans, Transparent, A
  226.     If Trans =
  227.         Trans := 255
  228.  
  229.     Trans := Trans + 17
  230.     If Trans > 255
  231.       WinSet, Transparent, OFF, A
  232.     Else
  233.       WinSet, Transparent, %Trans%, A
  234. Return
  235.  
  236. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  237. ; ----- Remove window frame
  238.  
  239. #!n::WinSet, Style, ^0xC00000, A
  240. ;#!n::
  241. ;   WinGet Style, Style, A
  242. ;   Style := Style ^0xC00000
  243. ;   WinSet, Style, %Style%, A
  244. ;Return
  245.  
  246.  
  247. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  248. ; ----- Alt-Drag  from http://www.autohotkey.com/docs/scripts/EasyWindowDrag.htm
  249. Alt & LButton::
  250.     CoordMode, Mouse  ; Switch to screen/absolute coordinates.
  251.     MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
  252.     WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
  253.     WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
  254.     if EWD_WinState = 0 ; Only if the window isn't maximized
  255.     {
  256.         SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
  257.     }
  258. Return
  259.  
  260. EWD_WatchMouse:
  261.     GetKeyState, EWD_LButtonState, LButton, P
  262.     if EWD_LButtonState = U  ; Button has been released, so drag is complete.
  263.     {
  264.         SetTimer, EWD_WatchMouse, off
  265.         return
  266.     }
  267.     GetKeyState, EWD_EscapeState, Escape, P
  268.     if EWD_EscapeState = D  ; Escape has been pressed, so drag is cancelled.
  269.     {
  270.         SetTimer, EWD_WatchMouse, off
  271.         WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
  272.         return
  273.     }
  274.     ; Otherwise, reposition the window to match the change in mouse coordinates
  275.     ; caused by the user having dragged the mouse:
  276.     CoordMode, Mouse
  277.     MouseGetPos, EWD_MouseX, EWD_MouseY
  278.     WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
  279.     SetWinDelay, -1   ; Makes the below move faster/smoother.
  280.     WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
  281.     EWD_MouseStartX := EWD_MouseX  ; Update for the next timer-call to this subroutine.
  282.     EWD_MouseStartY := EWD_MouseY
  283. Return
  284.  
  285.  
  286. ; ----------------------------------------------------- (#Win !Alt ^Ctrl +Shift)
  287. ; ----- Focus-less ScrollWheel from http://www.autohotkey.com/board/topic/6292-send-mouse-scrolls-to-window-under-mouse/page-9?hl=%2Bmouse+%2Bwheel#entry620251
  288.  
  289.  
  290. ;Function definitions
  291.  
  292. ;See above for details
  293. FocuslessScroll(MinLinesPerNotch, MaxLinesPerNotch, AccelerationThreshold, AccelerationType, StutterThreshold)
  294. {
  295.     SetBatchLines, -1 ;Run as fast as possible
  296.     CoordMode, Mouse, Screen ;All coords relative to screen
  297.    
  298.     ;Stutter filter: Prevent stutter caused by cheap mice by ignoring successive WheelUp/WheelDown events that occur to close together.
  299.     If(A_TimeSincePriorHotkey < StutterThreshold) ;Quickest succession time in ms
  300.         If(A_PriorHotkey = "WheelUp" Or A_PriorHotkey ="WheelDown")
  301.             Return
  302.  
  303.     MouseGetPos, m_x, m_y,, ControlClass2, 2
  304.     ControlClass1 := DllCall( "WindowFromPoint", "int64", (m_y << 32) | (m_x & 0xFFFFFFFF), "Ptr") ;32-bit and 64-bit support
  305.  
  306.     lParam := (m_y << 16) | (m_x & 0x0000FFFF)
  307.     wParam := (120 << 16) ;Wheel delta is 120, as defined by MicroSoft
  308.  
  309.     ;Detect WheelDown event
  310.     If(A_ThisHotkey = "WheelDown" Or A_ThisHotkey = "^WheelDown" Or A_ThisHotkey = "+WheelDown" Or A_ThisHotkey = "*WheelDown")
  311.         wParam := -wParam ;If scrolling down, invert scroll direction
  312.    
  313.     ;Detect modifer keys held down (only Shift and Control work)
  314.     If(GetKeyState("Shift","p"))
  315.         wParam := wParam | 0x4
  316.     If(GetKeyState("Ctrl","p"))
  317.         wParam := wParam | 0x8
  318.  
  319.     ;Adjust lines per notch according to scrolling speed
  320.     Lines := LinesPerNotch(MinLinesPerNotch, MaxLinesPerNotch, AccelerationThreshold, AccelerationType)
  321.  
  322.     If(ControlClass1 != ControlClass2)
  323.     {
  324.         Loop %Lines%
  325.         {
  326.             SendMessage, 0x20A, wParam, lParam,, ahk_id %ControlClass1%
  327.             SendMessage, 0x20A, wParam, lParam,, ahk_id %ControlClass2%
  328.         }
  329.     }
  330.     Else ;Avoid using Loop when not needed (most normal controls). Greately improves momentum problem!
  331.     {
  332.         SendMessage, 0x20A, wParam * Lines, lParam,, ahk_id %ControlClass1%
  333.     }
  334. }
  335.  
  336. ;All parameters are the same as the parameters of FocuslessScroll()
  337. ;Return value: Returns the number of lines to be scrolled calculated from the current scroll speed.
  338. LinesPerNotch(MinLinesPerNotch, MaxLinesPerNotch, AccelerationThreshold, AccelerationType)
  339. {
  340.     T := A_TimeSincePriorHotkey
  341.  
  342.     ;Normal slow scrolling, separationg between scroll events is greater than AccelerationThreshold miliseconds.
  343.     If((T > AccelerationThreshold) Or (T = -1)) ;T = -1 if this is the first hotkey ever run
  344.     {
  345.         Lines := MinLinesPerNotch
  346.     }
  347.     ;Fast scrolling, use acceleration
  348.     Else
  349.     {
  350.         If(AccelerationType = "P")
  351.         {
  352.             ;Parabolic scroll speed curve
  353.             ;f(t) = At^2 + Bt + C
  354.             A := (MaxLinesPerNotch-MinLinesPerNotch)/(AccelerationThreshold**2)
  355.             B := -2 * (MaxLinesPerNotch - MinLinesPerNotch)/AccelerationThreshold
  356.             C := MaxLinesPerNotch
  357.             Lines := Round(A*(T**2) + B*T + C)
  358.         }
  359.         Else
  360.         {
  361.             ;Linear scroll speed curve
  362.             ;f(t) = Bt + C
  363.             B := (MinLinesPerNotch-MaxLinesPerNotch)/AccelerationThreshold
  364.             C := MaxLinesPerNotch
  365.             Lines := Round(B*T + C)
  366.         }
  367.     }
  368.     Return Lines
  369. }
  370.  
  371. ;All hotkeys with the same parameters can use the same instance of FocuslessScroll().
  372. ; No need to have separate calls unless each hotkey requires different parameters (e.g. you want to disable acceleration for Ctrl-WheelUp and Ctrl-WheelDown).
  373. ; If you want a single set of parameters for all scrollwheel actions, you can simply use *WheelUp:: and *WheelDown:: instead.
  374.  
  375. #MaxThreadsPerHotkey 6 ;Adjust to taste. The lower the value, the lesser the momentum problem on certain smooth-scrolling GUI controls (e.g. AHK helpfile main pane, WordPad...), but also the lesser the acceleration feel. The good news is that this setting does no affect most controls, only those that exhibit the momentum problem. Nice.
  376. ;Scroll with acceleration
  377. WheelUp::
  378. WheelDown::FocuslessScroll(MinLinesPerNotch, MaxLinesPerNotch, AccelerationThreshold, AccelerationType, StutterThreshold)
  379. ;Ctrl-Scroll zoom with no acceleration (MaxLinesPerNotch = MinLinesPerNotch).
  380. ^WheelUp::
  381. ^WheelDown::FocuslessScroll(MinLinesPerNotch, MinLinesPerNotch, AccelerationThreshold, AccelerationType, StutterThreshold)
  382. ;If you want zoom acceleration, replace above line with this: FocuslessScroll(MinLinesPerNotch, MaxLinesPerNotch, AccelerationThreshold, AccelerationType, StutterThreshold)
  383. #MaxThreadsPerHotkey 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement