Create an Autohotkey script for me (consider the new syntax of the new version) which…
- User
Create an Autohotkey script for me (consider the new syntax of the new version) which loops 25 times this set of key presses: (Hold down CTRL for the entirety of the duration, so likely before the loop)
delay 100 milliseconds or 0.1 second between each input, so they never conflict (loop start) (press 1x Numpad 5) (Press 3x Numpad 6) (press 1x Numpad 5) (Press 3x Numpad 4) (delay 2000 milliseconds or 2 seconds) (loop end)
Assistant
Here's an AutoHotkey v2 script that does exactly what you described:
#Requires AutoHotkey v2.0 F1:: { ; Hold down Ctrl for the entire duration Send "{Ctrl down}" ; Loop 25 times Loop 25 { ; Press Numpad 5 once Send "{Numpad5}" Sleep 100 ; Press Numpad 6 three times Send "{Numpad6}" Sleep 100 Send "{Numpad6}" Sleep 100 Send "{Numpad6}" Sleep 100 ; Press Numpad 5 once Send "{Numpad5}" Sleep 100 ; Press Numpad 4 three times Send "{Numpad4}" Sleep 100 Send "{Numpad4}" Sleep 100 Send "{Numpad4}" Sleep 100 ; Wait 2 seconds before next iteration Sleep 2000 } ; Release Ctrl after all loops complete Send "{Ctrl up}" }This script:
- Uses F1 as the trigger key (press F1 to start the sequence)
- Holds Ctrl down for the entire duration using
{Ctrl down}and{Ctrl up} - Loops exactly 25 times
- Maintains 100ms delays between each key press
- Waits 2 seconds between each loop iteration
- Uses AutoHotkey v2 syntax throughout
To use it, save the code as a
.ahkfile and run it with AutoHotkey v2. Press F1 to trigger the sequence. You can change the trigger key (F1) to any other key if you prefer.- User
Okay, it seems that these numpad keys are not doing what I want in this script. I have setup the keyboard mouse configuration in windows which moves the cursor left on numpad 4 by a certain amount of pixels, and right by the same amount on numpad 6. Numpad 5 is left-click. How do I make the system register that these numpad keys are meant for the mouse movement, and not for their actual number value?
Assistant
The issue is that your script is sending the numpad keys as keyboard input, but you need Windows to interpret them as mouse keys through the Mouse Keys accessibility feature. Here are a couple of solutions:
Option 1: Use direct mouse commands instead of numpad keys
#Requires AutoHotkey v2.0 F1:: { ; Loop 25 times Loop 25 { ; Left click (equivalent to Numpad 5) Click Sleep 100 ; Move right 3 times (equivalent to 3x Numpad 6) MouseMove 10, 0, 0, "R" ; Adjust the "10" to match your pixel amount Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 ; Left click again Click Sleep 100 ; Move left 3 times (equivalent to 3x Numpad 4) MouseMove -10, 0, 0, "R" ; Negative value moves left Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 ; Wait 2 seconds before next iteration Sleep 2000 } }Option 2: If you must use the numpad keys with Mouse Keys enabled
#Requires AutoHotkey v2.0 F1:: { ; Ensure Mouse Keys is enabled first ; You may need to enable this manually in Windows Settings ; Loop 25 times Loop 25 { ; Send actual numpad key presses (not virtual key codes) SendInput "{Blind}{Numpad5}" Sleep 100 SendInput "{Blind}{Numpad6}" Sleep 100 SendInput "{Blind}{Numpad6}" Sleep 100 SendInput "{Blind}{Numpad6}" Sleep 100 SendInput "{Blind}{Numpad5}" Sleep 100 SendInput "{Blind}{Numpad4}" Sleep 100 SendInput "{Blind}{Numpad4}" Sleep 100 SendInput "{Blind}{Numpad4}" Sleep 100 Sleep 2000 } }I'd recommend Option 1 since it directly controls the mouse and will be more reliable. Just adjust the pixel values (the "10" in the MouseMove commands) to match the distance your Mouse Keys configuration moves the cursor.
- User
Great options! Can you tell me what the syntax is for making the script stop on a certain key - say ESCAPE? And resume as well on that same key
Assistant
Here's how to add pause/resume functionality with the ESCAPE key. I'll show you both options:
Option 1: With direct mouse commands + pause/resume
#Requires AutoHotkey v2.0 ; Global variable to track if script is paused isPaused := false F1:: { ; Reset pause state when starting global isPaused := false ; Loop 25 times Loop 25 { ; Check if paused before each action while (isPaused) { Sleep 50 ; Small delay while paused } ; Left click (equivalent to Numpad 5) Click Sleep 100 ; Move right 3 times (equivalent to 3x Numpad 6) MouseMove 10, 0, 0, "R" Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 ; Left click again Click Sleep 100 ; Move left 3 times (equivalent to 3x Numpad 4) MouseMove -10, 0, 0, "R" Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 ; Wait 2 seconds before next iteration (with pause checks) pauseCounter := 0 while (pauseCounter < 2000) { if (isPaused) { while (isPaused) { Sleep 50 } } Sleep 50 pauseCounter += 50 } } } ; ESC key to toggle pause/resume Esc:: { global isPaused := !isPaused if (isPaused) { ToolTip "Script PAUSED - Press ESC to resume" } else { ToolTip "Script RESUMED" SetTimer () => ToolTip(), -1000 ; Clear tooltip after 1 second } }Option 2: Simpler version that completely stops/restarts
#Requires AutoHotkey v2.0 ; Global variable to track if script should stop shouldStop := false F1:: { ; Reset stop flag global shouldStop := false ; Loop 25 times Loop 25 { ; Check if we should stop if (shouldStop) { ToolTip "Script STOPPED" SetTimer () => ToolTip(), -2000 return } ; Your actions here Click Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 Click Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 Sleep 2000 } ToolTip "Script COMPLETED" SetTimer () => ToolTip(), -2000 } ; ESC key to stop the script Esc:: { global shouldStop := true ToolTip "Stopping script..." SetTimer () => ToolTip(), -1000 }Key differences:
- Option 1 pauses and resumes exactly where it left off
- Option 2 completely stops the script, and you'd need to press F1 again to restart from the beginning
The first option is more sophisticated and probably what you want. Press ESC to pause, ESC again to resume. The script will show tooltips to indicate the current state.
- User
is the global variable necessary for this to work?
And what would an option look like that simply stops / exits?
Additionally, is there a way to stop AND CLOSE the script on a certain button press?
Assistant
Is the global variable necessary? Yes, the global variable is necessary for the pause/resume functionality because AutoHotkey hotkeys (like
Esc::) run in separate contexts from your main function. Withoutglobal, the variable wouldn't be shared between the F1 function and the Esc function.Option for simple stop/exit:
#Requires AutoHotkey v2.0 ; Global variable to stop the loop shouldStop := false F1:: { global shouldStop := false Loop 25 { if (shouldStop) return ; Exit the function completely Click Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 Click Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 Sleep 2000 } } Esc:: { global shouldStop := true }Option to stop AND close the entire script:
#Requires AutoHotkey v2.0 F1:: { Loop 25 { Click Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 MouseMove 10, 0, 0, "R" Sleep 100 Click Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 MouseMove -10, 0, 0, "R" Sleep 100 Sleep 2000 } } ; ESC to completely exit/close the script Esc::ExitApp ; Alternative: Ctrl+Q to exit (common convention) ^q::ExitAppThe
ExitAppcommand immediately terminates the entire AutoHotkey script, so no global variable is needed for this approach. The script will completely close and you'd need to run it again to use it.- User
it's strange. I have made a screenshot of the UI I want to navigate using this script, and identified the pixel count using my picture editor paint.net. It should be exactly 180 pixels between the two buttons. Yet, if I set the value 180 in the script, it overshoots the button by about 20%. I have to set a value somewhere between 150 and 155 in order to hit the button. What could explain this divergence?
Assistant
This divergence is likely due to Windows display scaling (DPI scaling). Here are the most common causes:
1. Display Scaling (Most Likely Cause) If your Windows display scaling is set to anything other than 100%, it affects mouse movement calculations. For example:
- 125% scaling: Your 180 pixels becomes ~225 actual pixels moved
- 150% scaling: Your 180 pixels becomes ~270 actual pixels moved
Check your scaling: Right-click desktop → Display settings → Scale (it might show 125%, 150%, etc.)
2. Solutions:
Option A: Make AutoHotkey DPI-aware
#Requires AutoHotkey v2.0 ; Make the script DPI-aware DllCall("SetProcessDPIAware") F1:: { Loop 25 { Click Sleep 100 ; Now try your original 180 pixel value MouseMove 180, 0, 0, "R" Sleep 100 ; ... rest of your code } }Option B: Calculate the scaling factor
#Requires AutoHotkey v2.0 ; Get DPI scaling factor dpi := DllCall("GetDpiForWindow", "Ptr", WinGetID("A")) scaleFactor := dpi / 96.0 ; 96 is the standard DPI ; Adjust your pixel values adjustedPixels := Round(180 / scaleFactor) F1:: { Loop 25 { Click Sleep 100 MouseMove adjustedPixels, 0, 0, "R" Sleep 100 ; ... rest of your code } }Option C: Just use the value that works Since you found that 150-155 works, just use that! Sometimes the practical approach is best:
MouseMove 153, 0, 0, "R" ; Use whatever value actually worksThe DPI scaling explanation is why measuring pixels in an image editor doesn't always match the actual mouse movement needed in Windows applications.
- User
according to my windows display options, scaling is set to 100%. screen resolution 1920x1080. mouse acceleration is not enabled, as far as I can tell. I have modified the script as well to only have one single mouse movement, rather than 3 as before. The current script is: Loop 5 { ; Left click (equivalent to Numpad 5) Click Sleep 100
; Move right 3 times (equivalent to 3x Numpad 6) MouseMove 160, 0, 0, "R" ; Adjust the "10" to match your pixel amount Sleep 100 ; Left click again Click Sleep 100 ; Move left 3 times (equivalent to 3x Numpad 4) MouseMove -160, 0, 0, "R" ; Negative value moves left Sleep 100 ; Wait 2 seconds before next iteration Sleep 2000 }}
Assistant
Since your scaling is at 100% and you're still seeing this discrepancy, here are the most likely causes:
1. Browser/Application Zoom If you're automating a web browser or application, check if it has its own zoom level:
- Browser: Look for zoom percentage in address bar (should be 100%)
- Applications: Check View menu for zoom settings
2. Mouse Speed/Sensitivity Settings Even with acceleration disabled, Windows mouse speed can affect pixel-perfect movement:
- Go to Settings → Mouse → Additional mouse options
- Check the "Pointer speed" slider - it should be in the middle (6/11) for 1:1 pixel movement
3. Application-Specific Scaling Some applications have their own DPI handling. Try this enhanced script that forces more precise movement:
#Requires AutoHotkey v2.0 F1:: { ; Force DPI awareness DllCall("SetProcessDPIAware") Loop 5 { Click Sleep 100 ; Use CoordMode to ensure screen coordinates CoordMode "Mouse", "Screen" ; Get current position and calculate exact target MouseGetPos ¤tX, ¤tY targetX := currentX + 180 ; Move to exact position MouseMove targetX, currentY, 0 Sleep 100 Click Sleep 100 ; Move back to original position MouseMove currentX, currentY, 0 Sleep 100 Sleep 2000 } } Esc::ExitApp4. Quick Test Try this simple test to verify your pixel measurements:
F1:: { MouseGetPos &startX, &startY MouseMove startX + 180, startY, 0 MsgBox "Moved 180 pixels right. Did it land correctly?" }The fact that 160 works instead of 180 suggests either the application has some internal scaling/padding, or there's a mouse sensitivity setting affecting the movement. The enhanced script above should give you more precise control.
- User
test, are you still there?
Assistant
Yes, I'm still here! How can I help you?
- User
I want to search multiple different files with the same search string in windows explorer. This string here works for up to 2 different files, but it does not work for multiple This works: name:170712 OR 170707 This does not work: name:170712 OR 170707 OR 170532 OR 170422 OR 170417 OR 170406 OR 170311 OR 170055 OR 170044 OR 170038 OR 170022 OR 170011 OR 170005 OR 160926 OR 165451 OR 165137 OR 164223 OR 164203 OR 163948 OR 163855 OR 163729 OR 163319 OR 163117
Assistant
The issue is likely that Windows Explorer has a character limit for search queries, and your long OR chain is exceeding it. Here are several solutions:
Solution 1: Use wildcards with common patterns If your numbers follow patterns, you can use wildcards:
name:170* OR name:16*Solution 2: Break into multiple searches Split your search into smaller groups:
name:170712 OR 170707 OR 170532 OR 170422 OR 170417Then repeat with the next batch.
Solution 3: Use PowerShell (more powerful) Open PowerShell in your target folder and use:
Get-ChildItem | Where-Object {$_.Name -match "170712|170707|170532|170422|170417|170406|170311|170055|170044|170038|170022|170011|170005|160926|165451|165137|164223|164203|163948|163855|163729|163319|163117"}Solution 4: Use Everything search tool Download the free "Everything" search tool - it handles complex queries much better than Windows Explorer and doesn't have the same limitations.
Solution 5: Try parentheses grouping Sometimes this helps with parsing:
name:(170712 OR 170707 OR 170532 OR 170422)Solution 6: Use file extensions if applicable If these are specific file types:
*.txt AND name:(170712 OR 170707 OR 170532)The PowerShell solution (#3) is probably your best bet for handling all those numbers at once reliably.
- User
This -> name:170712,170707,170532,170422,170417,170406,170311,170055,170044,170038,170022,170011,170005,160926,165451,165137,164223,164203,163948,163855,163729,163319,163117 <- does not work either. However, putting paranthesis () around this -> name:(170712 OR 170707 OR 170532 OR 170422 OR 170417 OR 170406 OR 170311 OR 170055 OR 170044 OR 170038 OR 170022 OR 170011 OR 170005 OR 160926 OR 165451 OR 165137 OR 164223 OR 164203 OR 163948 OR 163855 OR 163729 OR 163319 OR 163117) <- does work. What difference are the () making to overcome the limitation of the OR search term?
Assistant
Great discovery! The parentheses are making a crucial difference in how Windows Explorer parses and processes the search query. Here's what's happening:
Without parentheses:
name:170712 OR 170707 OR 170532 OR ...Windows Explorer interprets this as:
name:170712OR170707(searches everywhere, not just filename) OR170532(searches everywhere, not just filename) OR ...
This creates a much more complex query that searches file contents, metadata, and other properties for each term after the first one, which can overwhelm the search engine.
With parentheses:
name:(170712 OR 170707 OR 170532 OR ...)Windows Explorer interprets this as:
- Apply the
name:filter to the entire grouped expression - Only search within filenames for any of the terms in the parentheses
The parentheses essentially:
- Scope the search properly - keeps everything within the filename search
- Create a single logical unit - the search engine processes it as one cohesive query rather than multiple separate conditions
- Reduce complexity - prevents the search from expanding beyond filenames
- Improve parsing efficiency - gives the query parser clear boundaries to work with
This is why your parentheses version works while the others fail. It's a much cleaner and more efficient query structure that stays within Windows Explorer's processing capabilities.
- User
Thanks!
Assistant
You're welcome! Glad I could help explain why the parentheses made the difference. It's one of those quirky search syntax things that's really useful to know. Feel free to ask if you run into any other issues!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.