Temporarily Pause Autofire loop on holding button - autohotkey

I wrote a script that sends autofire left clicks and can be triggered on and off. The script works. However, the problem is that holding the right mouse button does not work properly anymore because the left click keeps getting sent. So I want to change the script that it gets temporarily paused while I hold down the right mouse button.
How would I go about doing this? Here is my current code:
#MaxThreadsPerHotkey 3
#z::
#MaxThreadsPerHotkey 1
if keep_winz_running = y
{
keep_winz_running = n
return
}
; Otherwise:
keep_winz_running = y
Loop
{
GetKeyState, rbut, Rbutton
If rbut, = U
{
Loop,
{
MouseClick, left
Sleep, 50 ;This means the script will wait 1.5 secs
if keep_winz_running = n ; The user signaled the loop to stop.
break ; break out of the loop
}

Timers are the best!
sendToggle := false
#z::
if(!sendToggle) {
sendToggle := true
SetTimer, SendClick, 100
} else {
sendToggle := false
SetTimer, SendClick, Off
}
return
#If sendToggle
RButton::
SetTimer, SendClick, Off
KeyWait, RButton
SetTimer, SendClick, 100
return
SendClick:
Click
return
I find the send interval of 50 ms awfully fast, especially since you won't be able to actually reach 50 ms without reducing SetBatchLines and SetKeyDelay. If it really needs to be that fast, consider changing them.

Related

Multiple loops with timers

So I'm new to AutoHotkey and I'm having some issues with the Multiloop timer thing, it works fine as first but on the second loop forward the times don't match up with what I want.
So basically I want the loops to run for 5min the loopTwo should be the first one out after 7s and then 2 seconds later I want the loopOne to be called in loopOne I have a 1.2s delay between presses, the first time it works correctly but then the times starts to shift and everything joins in a mess
F1::
If (loopOne = True)
{
SetTimer loopTwo, Off
TwoSwitch := False
SetTimer loopOne, Off
OneSwitch := False
} else {
TheTwoTime := 0
SetTimer loopTwo, 7000 ;run every 7s
TwoSwitch := True
TheOneTime := 0
SetTimer loopOne, 9000 ;run every 9s
OneSwitch := True
}
return
loopOne:
Send, 1
Sleep, 1200
Send, 1
TheOneTime ++
If TheOneTime >= 300 ;run for 5 minutes
{
SetTimer loopOne, Off
OneSwitch := False
}
return
loopTwo:
Send, 2
Sleep, 2000
TheTwoTime ++
If TheOneTime >= 300 ;run for 5 minutes
{
SetTimer loopTwo, Off
TwoSwitch := False
}
return
I think this is what you were trying to do. I don't see any need for two timers, assuming I understood your thing correctly.
Also ditched the legacy labels and switched over to SendInput due it to being the preferred faster and more reliable send mode.
Should be a pretty straight forward script apart from toggling with toggle:=!toggle. If you can't understand it, you can see an old answer of mine that has a bit about it here.
Also note the usage of a negative period in a timer, it's a very useful thing.
F1::
if (toggle:=!toggle)
{
SetTimer, MyCoolLoop, 7000 ;7sec period
SetTimer, StopLooping, -300000 ;negative period, run ONCE after 5mins
}
else
SetTimer, MyCoolLoop, Off
return
MyCoolLoop()
{
;number 2 gets sent (every 7secs)
;2secs after this, number 1 gets sent
;1.2secs after this, number 1 gets sent again
;3.8secs after this, we start from the beginning
SendInput, 2
Sleep, 2000
SendInput, 1
Sleep, 1200
SendInput, 1
}
StopLooping()
{
SetTimer, MyCoolLoop, Off
}

AHK blocked input

So I am making my script
toggl:=false
while(1){
if(toggl){
Send,E
}
Sleep, 150
}
!r::
toggl:=!toggl
return
!y::ExitApp,101
Problem is that while the loop is running, I can not cancel it because it blocks !y, so I had to restart computer. So any help with this would be nice.
Set #MaxThreads 2 to allow each hotkey to run twice, OR:
Use SetTimer to allow the hotkey to end and continue your loop in a "Pseudo-Thread".
toggle := 0
F12::
toggle := !toggle
if (toggle){
SetTimer, DoLoop, -100
}
return
DoLoop:
Loop {
if (!toggle){
break
}
; [Do your stuff here]
}
return

Can someone help me with this AHK Script

I want this Autohotkey script to press the spacebar automatically with a toggle option so i dont have to hold the spacebar all the time. The toggle key should be the middle mouse button. Could you please write it correctly for me? Because the toggle part I found doesn't seem to work. Thanks in advance CptPrice :D
Main script:
*~$Space::
Sleep 100
Loop
{
GetKeyState, SpaceState, Space, P
If SpaceState = U
break
Sleep 5
Send, {Blind}{Space}
}
Toggle-part:
#MaxThreadsPerHotkey 2
MButton::
if (toggle := !toggle) {
; on
} else {
; off
}
return
toggle := false
return
MButton:: toggle := !toggle
#If toggle
#MaxThreadsPerHotkey 2
*~$Space::
Sleep 100
Loop
{
Sleep 5
Send, {Blind}{Space}
if (!toggle) ; Press MButton to break
break
}
return
#If

pixelsearch and click right pixel

IF NOT A_IsAdmin ; Runs script as Admin.
{
Run *RunAs "%A_ScriptFullPath%"
ExitApp
}
#MaxThreadsPerHotkey, 2
CoordMode, Pixel, Screen
#singleInstance, Force
toggle = 0
upperLeftX := 750
upperLeftY := 400
lowerRightX := 850
lowerRightY := 500
F8:: ; press F8 to toggle the loop on/off.
SoundBeep
Toggle := !Toggle
While Toggle
{ ;-- Begin of loop.
PixelSearch, X, Y,%upperLeftX%, %upperLeftY%, %lowerRightX%, %lowerRightY%, 0x000000, 0, Fast RGB
IF ErrorLevel = 1 ; IF NOTFound.
{
sleep, 100
}
IF ErrorLevel = 0 ; IF Found.
{
MouseClick, left
sleep, 300
}
} ;-- End of Loop.
return
F8 starts loop and this code checks specific pixel in rectangle and sends left click.
It works with [MouseClick, left, %X%, %Y%].But I want to know how can I use dllcall mouse event to click on specific pixel.
for example
DllCall("mouse_event",uint,1,int,%X%,int,%Y%,uint,0,int,0)
But its not working
I doubt that you actually want to do this via DLL calls. mouse_event doesn't even take coordinates, but values between 0-65535.
If you want to be able to click any pixel on the screen make sure you set it to be relative to the screen: CoordMode, Mouse, Screen
Then use ControlClick/PostMessage/SendMessage if you don't want to affect your mouse pointer by that click. Or use MouseClick/Click. Or MouseMove+Send, {LButton}.

Can someone help me an AutoHotKey script?

I've read the help and guide for it but I just can't figure it out. All I want to do is create a hotkey that when pressed will move my mouse until the hotkey is pressed again. Can anyone tell me how to do this? It should be really simple but apparently I'm missing something.
This is pretty much the most annoying HotKey ever, but here you go (hotkey is Ctrl+Alt+C);
#MaxThreadsPerHotkey 3
^!c::
#MaxThreadsPerHotkey 1
if DoMouseMove
{
DoMouseMove := false
return
}
DoMouseMove := true
Loop
{
Sleep 100
Random, randX, 1, 1028
Random, randY, 1, 800
MouseMove, randX, randY, 25
Sleep, 100
if not DoMouseMove
break
}
DoMouseMove := false
return
I will throw in my solution.
pause::
If (Toggle := !Toggle) ; Toggle the value True/False
{
ToolTip Mouse Mover,A_ScreenWidth/2,0 ; Show that Mouse Mover is active
SetTimer MoveMouse, 1000 ; 1000 ms = 1 sec. Every minute (60000 ms) is probably enough.
}
Else
{
Tooltip ; Turn Mouse Mover alert window off
SetTimer MoveMouse, Off ; Turn the timer off
}
return
MoveMouse:
MouseMove, 1, 0, 1, R ;Move the mouse one pixel to the right
Sleep, 50 ; Wait 50 ms. Not realy required, but makes the move visible
MouseMove, -1, 0, 1, R ;Move the mouse back one pixel
return