AutoHotKey (AHK)

clickhappier

┬──┬ ノ( ゜-゜ノ)
Subforum Curator
Crowd Pleaser
Joined
Jan 12, 2016
Messages
728
Reaction score
1,634
Points
593
Location
USA
Feel free to share AHK scripts here! Just make sure any 'submit' step is a separate keystroke, not auto-submitting before you have a chance to check your work.


AutoHotKey (AHK) Learning Resources

Some AutoHotKey reference sources:
 

clickhappier

┬──┬ ノ( ゜-゜ノ)
Subforum Curator
Crowd Pleaser
Joined
Jan 12, 2016
Messages
728
Reaction score
1,634
Points
593
Location
USA
1/26/16 MTC:

I suck at AHK but I'm ok with Tampermonkey style scripts.
I mean AHK is literally just mimicking what you do on your keyboard and is pretty much written like English.

What you do is go to a hit and figure out what you need to do on your keyboard, and then convert that to AHK.

An example: Say you need to check a button on a page and want to select the 4th option to the right. You determine that to get to the row of buttons you need to press tab 5 times. So that becomes Send {Tab 5}. Then you want to get to Option 4, which you realize after pressing Tab 5 times, you need to press the Right Key 3 times. So that becomes Send {Right 3}. Just follow this style for writing AHK scripts
 

TSolo315

SnapNCrackle
Administrator
Joined
Jan 12, 2016
Messages
5,000
Reaction score
16,975
Points
2,538
Gender
Male
Code:
^+8::
InputBox, opener, Open AHK, Script Name:,, 150, 150,
sleep 50
if opener =
{
return
}
else
{
run C:\****YOUR AHK DIRECTORY GOES HERE*****\%opener%.ahk,,UseErrorLevel,
if ErrorLevel
{
MsgBox, The script does not exist.
return
}
}
opener =
return
Quick AHK for people with a lot of AHK scripts in the same directory/folder. Simply replace "C\****YOUR AHK DIRECTORY GOES HERE*****\" with your AHK directory.

When you hit the hotkey, an inputbox will appear. Simply enter an AHK script name and it will be opened for you.

Hotkey used here is control + shift + 8
 
Last edited:

rosesword975

Off with their HEADS!!
Contributor
Joined
Mar 17, 2016
Messages
30
Reaction score
61
Points
343
Age
47
Gender
Female
Code:
;Title - Spitch Ag - Transcribe short audio recordings of spoken digit sequences (English)
;creator - rosesword975
;description - use your numpad to enter the numbers spelled out.
;mturkcrowd.com
;http://www.mturkcrowd.com/posts/159567/

numpad0::Send zero{Space}
numpad1::Send one{Space}
numpad2::Send two{Space}
numpad3::Send three{Space}
numpad4::Send four{Space}
numpad5::Send five{Space}
numpad6::Send six{Space}
numpad7::Send seven{Space}
numpad8::Send eight{Space}
numpad9::Send nine{Space}
numpadDot::Send oh{Space}
numpadAdd::Send double{Space}
numpadSub::Send XX{Space}
 

TSolo315

SnapNCrackle
Administrator
Joined
Jan 12, 2016
Messages
5,000
Reaction score
16,975
Points
2,538
Gender
Male
Here is a cool AHK script I've been using for a while. Lets you scroll in a window without activating it (will also make scrolling faster for most people.) I personally have this run on startup.

Code:
;Directives
#NoEnv
#SingleInstance Force
#MaxHotkeysPerInterval 200 ;Avoid warning when mouse wheel turned very fast

;Autoexecute code
MinLinesPerNotch := 1
MaxLinesPerNotch := 5
AccelerationThreshold := 100
AccelerationType := "L" ;Change to "P" for parabolic acceleration
StutterThreshold := 10

;Function definitions

;See above for details
FocuslessScroll(MinLinesPerNotch, MaxLinesPerNotch, AccelerationThreshold, AccelerationType, StutterThreshold)
{
   SetBatchLines, -1 ;Run as fast as possible
   CoordMode, Mouse, Screen ;All coords relative to screen
  
   ;Stutter filter: Prevent stutter caused by cheap mice by ignoring successive WheelUp/WheelDown events that occur to close together.
   If(A_TimeSincePriorHotkey < StutterThreshold) ;Quickest succession time in ms
     If(A_PriorHotkey = "WheelUp" Or A_PriorHotkey ="WheelDown")
       Return

   MouseGetPos, m_x, m_y,, ControlClass2, 2
   ControlClass1 := DllCall( "WindowFromPoint", "int64", (m_y << 32) | (m_x & 0xFFFFFFFF), "Ptr") ;32-bit and 64-bit support

   lParam := (m_y << 16) | (m_x & 0x0000FFFF)
   wParam := (120 << 16) ;Wheel delta is 120, as defined by MicroSoft

   ;Detect WheelDown event
   If(A_ThisHotkey = "WheelDown" Or A_ThisHotkey = "^WheelDown" Or A_ThisHotkey = "+WheelDown" Or A_ThisHotkey = "*WheelDown")
     wParam := -wParam ;If scrolling down, invert scroll direction
  
   ;Detect modifer keys held down (only Shift and Control work)
   If(GetKeyState("Shift","p"))
     wParam := wParam | 0x4
   If(GetKeyState("Ctrl","p"))
     wParam := wParam | 0x8

   ;Adjust lines per notch according to scrolling speed
   Lines := LinesPerNotch(MinLinesPerNotch, MaxLinesPerNotch, AccelerationThreshold, AccelerationType)

   If(ControlClass1 != ControlClass2)
   {
     Loop %Lines%
     {
       SendMessage, 0x20A, wParam, lParam,, ahk_id %ControlClass1%
       SendMessage, 0x20A, wParam, lParam,, ahk_id %ControlClass2%
     }
   }
   Else ;Avoid using Loop when not needed (most normal controls). Greately improves momentum problem!
   {
     SendMessage, 0x20A, wParam * Lines, lParam,, ahk_id %ControlClass1%
   }
}

;All parameters are the same as the parameters of FocuslessScroll()
;Return value: Returns the number of lines to be scrolled calculated from the current scroll speed.
LinesPerNotch(MinLinesPerNotch, MaxLinesPerNotch, AccelerationThreshold, AccelerationType)
{
   T := A_TimeSincePriorHotkey

   ;Normal slow scrolling, separationg between scroll events is greater than AccelerationThreshold miliseconds.
   If((T > AccelerationThreshold) Or (T = -1)) ;T = -1 if this is the first hotkey ever run
   {
     Lines := MinLinesPerNotch
   }
   ;Fast scrolling, use acceleration
   Else
   {
     If(AccelerationType = "P")
     {
       ;Parabolic scroll speed curve
       ;f(t) = At^2 + Bt + C
       A := (MaxLinesPerNotch-MinLinesPerNotch)/(AccelerationThreshold**2)
       B := -2 * (MaxLinesPerNotch - MinLinesPerNotch)/AccelerationThreshold
       C := MaxLinesPerNotch
       Lines := Round(A*(T**2) + B*T + C)
     }
     Else
     {
       ;Linear scroll speed curve
       ;f(t) = Bt + C
       B := (MinLinesPerNotch-MaxLinesPerNotch)/AccelerationThreshold
       C := MaxLinesPerNotch
       Lines := Round(B*T + C)
     }
   }
   Return Lines
}

;All hotkeys with the same parameters can use the same instance of FocuslessScroll(). 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). If you want a single set of parameters for all scrollwheel actions, you can simply use *WheelUp:: and *WheelDown:: instead.

#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.
;Scroll with acceleration
WheelUp::
WheelDown::FocuslessScroll(MinLinesPerNotch, MaxLinesPerNotch, AccelerationThreshold, AccelerationType, StutterThreshold)
;Ctrl-Scroll zoom with no acceleration (MaxLinesPerNotch = MinLinesPerNotch).
^WheelUp::
^WheelDown::FocuslessScroll(MinLinesPerNotch, MinLinesPerNotch, AccelerationThreshold, AccelerationType, StutterThreshold)
;If you want zoom acceleration, replace above line with this:
;FocuslessScroll(MinLinesPerNotch, MaxLinesPerNotch, AccelerationThreshold, AccelerationType, StutterThreshold)
#MaxThreadsPerHotkey 1 ;Restore AHK's default  value i.e. 1
 
  • Like
Reactions: jml