limited vs continuous mouse click on a single hotkey plus exit on mouse move X pixels

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ronaldl
Posts: 4
Joined: 10 Oct 2017, 03:06

limited vs continuous mouse click on a single hotkey plus exit on mouse move X pixels

10 Oct 2017, 12:10

Hello,

I need help with my script. I want a script that can do:
a. X amount of mouse click on where the cursor position is.
b. Continuous mouse click on where the cursor position is (could be a different hotkey but i prefer it if the hotkey was the same and was long pressed)
c. able to detect mouse movement when greater than X amount of pixels exits the script. (actually i just want it to detect if somebody used the computer but don't want it to be too sensitive).

So far i was able to get a. done. Can anybody help complete the rest? I'm still learning.

Code: Select all

^`::
loop 50     ;my X variable for the amount of clicks
{
	click
	sleep 25  ; delay so computer can process the clicks
}
Return

Escape:: 	; added this because sometimes i make mistake and can't exit the script.
ExitApp
Return
User avatar
KuroiLight
Posts: 328
Joined: 12 Apr 2015, 20:24
Contact:

Re: limited vs continuous mouse click on a single hotkey plus exit on mouse move X pixels

10 Oct 2017, 16:00

to detect if there was computer input you can compare A_TimeIdle to A_TickCount (these values are in milliseconds) to get how long the computers been idle (nobody has moved mouse or typed keyboard.)
e.g. SecondsSinceLastInput := (A_TickCount - A_TimeIdle) / 1000
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
ronaldl
Posts: 4
Joined: 10 Oct 2017, 03:06

Re: limited vs continuous mouse click on a single hotkey plus exit on mouse move X pixels

12 Oct 2017, 12:34

Hi KuroiLight,

Thank you so much for your solution. Ordinarily this may work, but the reason i was looking for x pixels of movement is because I don't want the mousemove to be so sensitive that if somebody bumps the table the script will exit.

Can somebody share another solution? Also still need an answer for requirement "b".
User avatar
KuroiLight
Posts: 328
Joined: 12 Apr 2015, 20:24
Contact:

Re: limited vs continuous mouse click on a single hotkey plus exit on mouse move X pixels

13 Oct 2017, 13:27

for c:
after comparing A_TimeIdle and A_TickCount like I post before, also compare MouseGetPos results before and after and just ignore if it isn't over your required threshold.
I actually wanted to add the same functionality to an afk script I have, so I decided to write everything from scratch so we can both use it.
Unfortunately I couldn't think of a simple way to detect mouse movement and keyboard presses separately using A_TimeIdle without using dllcalls, so I ended up just hotkeying all keys.

change as you see fit

Code: Select all

CoordMode, Mouse. Screen
#UseHook, On
#Persistent

timeTilAFK := 5 ;time in seconds til we are AFK (5 for testing purposes)
mouseMoveThreshold := 25 ;how much movement is required, in pixel coordinates (x or y)
keypressed := false

SetTimer, checkForAFK, 1000
return

checkForAFK() {
    static afk := false

    if(!afk and IdleTimedOut()) {
        SetIdleMode(true)
        afk := true
    }

    if(afk) {
        if(!IsIdle()) {
            SetIdleMode(false)
            afk := false
        }
    }
    
    ;ToolTip, % "We are " . (afk ? "" : "not ") . "afk.", 0, 40, 1
}

IdleTimedOut() {
    global timeTilAFK
    timeBeenAFK := Round(A_TimeIdle / 1000)
    ;ToolTip, % timeBeenAFK, 0, 0, 2
    if(timeBeenAFK > timeTilAFK)
        return true
    else
        return false
}

SetIdleMode(onoff) {
    global keypressed
    Loop, 255
    {
        Hotkey, % "~" . Format("vk{:x}", A_Index), kp, % (onoff ? "On" : "Off")
    }
    keypressed := false
}

kp:
    keypressed := true
return

IsIdle() {
    global keypressed, mouseMoveThreshold
    static idle_x, idle_y
    if(idle_x == "" or idle_y == "") ;init if they havent been
        MouseGetPos, idle_x, idle_y

    MouseGetPos, n_x, n_y
    if(n_x != idle_x or n_y != idle_y) {
        ;check for our mouse movement is over threshold
        if(Abs(n_x - idle_x) > mouseMoveThreshold or Abs(n_y - idle_y) > mouseMoveThreshold)
            keypressed := true ;borrow this variable so just incase we want to cleanup
        idle_x := n_x, idle_y := n_y
    }

    if(keypressed)
        return false
    return true
}
as for B, if you talking about a simple toggle-able auto-clicker then here you go: (change F3 to what ever key you want to toggle with)

Code: Select all

click_length := 25 ;milliseconds [how long the click should be held down]
click_delay := 50 ;milliseconds [time between clicks]

F3::
    ac_toggle := !ac_toggle
    SetTimer, autoClick, % (ac_toggle ? click_delay : "Off")
return

autoClick:
    Click,,,,Down
    Sleep, %click_length%
    Click,,,,Up
return
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: DecimalTurn, Google [Bot], macromint, peter_ahk and 342 guests