Could someone help me understand how to capture Rbutton in Loop?
The idea is when I click GUI button its activate loop and waiting for some time for example 15 sec until RButton will be clicked, if loop detects that RBUtton been doubleclicked, should show me msg box
w::SetTimer Test, 5000
Test:
Loop { ; waiting when RButton will be clicked
Keywait,RButton
A := GetKeyState("Rbutton","P")
if (!%A%) {
MsgBox, this part should continue and wait for RButton do nothing and continue to wait
} else if (%A%) {
MsgBox, you clicked double RButton
Send, this is text
break
}
}
Msgbox end of script
SetTimer Test, Off
Return
My idea:
Use While loop as timer, ie, while within duration (eg 15 secs), keep checking status of double right button. If criteria met within duration, break the loop and show message box.
Use SetTimer and GetKeyState to constantly check and update number of right button clicked.
Note to below script. It is assumed that when GUI is clicked, DetectDoubleClick() will be fired.
Counter_RButton := 0
SecondsToWait := 15
DetectDoubleClick()
{
Global Counter_RButton
Now := A_TickCount
End := A_TickCount + (SecondsToWait * 1000)
SetTimer, CaptureRButton, 150
While (End >= Now)
{
if (Counter_RButton = 2)
{
Counter_RButton := 0
MsgBox,,,Double RButton Detected!
break
}
Now := A_TickCount
}
SetTimer, CaptureRButton, Off
return
}
CaptureRButton:
ButtonIsDown := GetKeyState("RButton")
If ButtonIsDown
Counter_RButton := Counter_RButton + 1
Exit
Goal of a code:
Timer CheckStart iterrates every 3 seconds until it find a choosen color.
If it finds pixel - it stops itself and start CheckStop timer, to look for another pixel every 3 seconds.
Rince and repeat
Also there is a keybind to check which timer was launched last.
#NoEnv
SendMode Input
checkstate = 0 ;just for checking state
SetTimer, CheckStart, 3000
Return
CheckStart:
PixelSearch, xx, zz, 710, 460, 730, 480, 0x385982, 0, Alt RGB
if !ErrorLevel {
checkstate = 1
SetTimer, CheckStart, Off
SetTimer, CheckEnd, 3000
Gosub, CheckEnd
}
Return
CheckEnd:
PixelSearch, xx, zz, 670, 160, 725, 200, 0xE60014, 0, Alt RGB
if !ErrorLevel {
checkstate = 0
SetTimer, CheckEnd, Off
SetTimer, CheckStart, 3000
Gosub, CheckStart
}
Return
^!z:: ; Control+Alt+Z
MouseGetPos, MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%, Alt RGB
MsgBox (checkstate%) colour: %color%.
return
What I'm getting:
Before i feed needed color to 1st timer, keybind works delayed, shows state only between iterrations. Can i make it async?
After i feed needed color to 1st timer, checker became "1", but CheckEnd timer not starting. (and so keybind start to work immediately)
What i'm doing wrong? or its just prohibited to launch timer by timer?
There is no such pixel search mode as Alt, that's only for PixelGetColor.
I'm going to assume the problem here is just the pixel search taking forever.
Add in the Fast mode.
So instead of Alt RGB try Fast RGB.
I'm trying to run my loop for two seconds. Within those two seconds, if I click left a message box gets activated, telling me that I've clicked left. If the 2 seconds are up another message box is supposed to appear, telling me that I've been waiting enough. However, after 2 seconds nothing happens ;(
:*:tcc::
start := A_TickCount
totalTime := stop - start
Loop {
stop := A_TickCount
if (totalTime > 2000)
{
MsgBox, enough waiting!
return
}
else if GetKeyState("LButton")
{
MsgBox, you clicked left
return
}
}
The variable "totalTime" has to be created within the loop, every time the loop stops:
:*:tcc::
start := A_TickCount
Loop {
stop := A_TickCount
totalTime := stop - start
if (totalTime > 2000)
{
MsgBox, enough waiting!
return
}
else if GetKeyState("LButton")
{
MsgBox, you clicked left
return
}
}
return
I am having a problem with my script which stops working properly, roughly after every 20-30 minutes of running. The problem seems to be with the loop that i have constructed and it stopping after that specific time. It's not the entire script that stops working because for example when i press another bind on caps lock it behaves normally. Furthermore when reloading the autohotkey script i get a message that "The script could not be reloaded." which I have never experienced before this problem with the loop.
So here's the code:
#IfWinActive Tibia
SplashTextOn, 100, 40, Running, WASD
WinMove, Running,, 1, 21
;SUSPEND AND INFORMATION===================================================
CapsLock::
Suspend
Toggle := !Toggle
if (Toggle = 0)
SplashTextOn, 90, 25, Running, WASD
WinMove, Running,, 1, 27
if (Toggle = 1)
{
SplashTextOn, 120, 40, NOT RUNNING, TYPING
WinMove, NOT RUNNING,, 1497, 69
}
return
NumpadAdd::
MsgBox, You have 0.5 seconds to mouse over MAIN BACKPACK.
Sleep, 500
MouseGetPos, mainbpxpos, mainbpypos
MsgBox, You have 0.5 seconds to mouse over MAIN SLOT BACKPACK.
Sleep, 500
MouseGetPos, mainbpslotxpos, mainbpslotypos
MsgBox, You have 0.5 seconds to mouse over FOOD.
Sleep, 500
MouseGetPos, foodxpos, foodypos
MsgBox, You have 0.5 seconds to mouse over HAND.
Sleep, 500
MouseGetPos, handxpos, handypos
MsgBox, You have 0.5 seconds to mouse over BLANK on GROUND.
Sleep, 500
MouseGetPos, blankgroundxpos, blankgroundypos
MsgBox, You have 0.5 seconds to mouse over LAST BLANK.
Sleep, 500
MouseGetPos, lastblankxpos, lastblankypos
MsgBox, You have 0.5 seconds to mouse over MADE RUNES POS.
Sleep, 500
MouseGetPos, maderunesxpos, maderunesypos
MsgBox, You have 0.5 seconds to mouse over RUNBACK POSITION (OUT HOUSE).
Sleep, 500
MouseGetPos, runbackxpos, runbackypos
MsgBox, You have 0.5 seconds to mouse over RUN POSITION (IN HOUSE).
Sleep, 500
MouseGetPos, runxpos, runypos
InputBox, blankrunesleft, Blank runes left, Enter the blank runes left, , 200, 170
MsgBox, SCRIPT IS ABOUT TO RUN, CLOSE ALL BPS!
BreakLoop = 0
iamout = 0
enemy = 0
Loop
{
if (BreakLoop = 1) {
break
}
Loop, %blankrunesleft%
{
if (BreakLoop = 1) {
break
}
SetMouseDelay, 5
battleOne := ReadMemory(0x5C6950,"Tibia")
;Notify(battleOne)
if (battleOne > 0) {
MouseClick, left, runxpos, runypos
Sleep, 30000
MouseClickDrag, left, mainbpslotxpos, mainbpslotypos, blankgroundxpos, blankgroundypos
Sleep, 400
Send, {Control Down}g{Control Up}
Sleep, 200
Send, {Enter}
Sleep, 5000
iamout = 0
}
if (battleOne == 0) {
if (iamout == 0) {
MouseClick, right, mainbpxpos, mainbpypos
Sleep, 200
MouseClick, right, blankgroundxpos, blankgroundypos
Sleep, 200
MouseClickDrag, left, blankgroundxpos, blankgroundypos, mainbpslotxpos, mainbpslotypos
Sleep, 200
MouseClick, left, runbackxpos, runbackypos
iamout = 1
Sleep, 500
}
}
mana := ReadMemory(0x5C682C,"Tibia")
if (iamout == 1) {
if (mana > 999) {
MouseClick, right, foodxpos, foodypos
Sleep, 60
MouseClick, right, foodxpos, foodypos
Sleep, 60
MouseClick, right, foodxpos, foodypos
Sleep, 100
MouseClickDrag, left, lastblankxpos, lastblankypos, handxpos, handypos
Sleep, 350
Send, Adori Vita Vis
Sleep, 100
Send, {Enter}
Sleep, 500
MouseClickDrag, left, handxpos, handypos, lastblankxpos, lastblankypos
Sleep, 350
blankrunesleft -= 1
}
}
if (iamout == 1) {
if (blankrunesleft == 0) {
Sleep, 100
MouseClick, left, runxpos, runypos
Sleep, 2000
MouseClickDrag, left, mainbpslotxpos, mainbpslotypos, maderunesxpos, maderunesypos
Sleep, 400
MouseClick, right, mainbpxpos, mainbpypos
Sleep, 500
blankrunesleft = 20
iamout = 0
}
}
}
}
Esc::
BreakLoop = 1
return
#IfWinActive
Edit: To add up, I have restarted the pc and done 2 more tests on this script. The result was that it always stops running properly, after exactly 22 minutes. I have no idea what could be causing this, would appreciate any help
Maybe if you rearranged things a little bit.
Move this to the top with your other hotkey routines; hotkeys should always be at the top of your script.
Esc::
BreakLoop = 1
return
put a return after the last {
This will keep the script from exiting when the loop ends.
As to your stopping every 22 minutes - is it possible that this is the length of the loop sequence? Since the timing seems consistent, you ought to be able to find the issue by keeping an eye out for simultaneous events.
Also, so can you tell what line the script is on when it says it won't reload? If you right-click on the tray icon and choose "Open" you will be able to see the status of the lines being processed.
That sort of debuggin method also shows you the time each line took to process and run. That may be very valuable in your case.
Goal of the script: to continually press Numpad0 for 10 seconds each time hotkey is pressed.
Current code:
toggle = 0
#MaxThreadsPerHotkey 2
timerToggle:
Toggle := !Toggle
sleep 10000
Toggle := !Toggle
F12::
SetTimer, timerToggle, -1
While Toggle{
send {NumPad0}
sleep 100
}
return
At present, the script will run as intended, but only once. Attempting to run it again after the first time does nothing. What am I missing?
I would rather use SetTimers instead of a 10 sec. long while like so
F12::
Send {Numpad0}
SetTimer, start, 100
SetTimer, stop, -10000
return
start:
Send {Numpad0}
return
stop:
SetTimer, start, off
return
Your script likely doesn't toggle your variable correctly. Here is a cleaner version of what you are trying to do which uses A_TickCount:
F12::SetTimer, HoldNumPad, -1
HoldNumPad:
kDown := A_TickCount
While ((A_TickCount - kDown) < 10000)
{
Send {Numpad0}
Sleep 100
}
Return
Note that pressing F12 while the label is running will not have any affect.
EDIT: Made SetTimer use -1 period to run only once, thanks to MCL.