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