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
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.
ArrayCount = 0
Loop, Read, Times.txt ; This loop retrieves each line from the file.
{
ArrayCount += 1 ; Keep track of how many items are in the array.
ArrayTime%ArrayCount% := A_LoopReadLine
}
WinGetTitle, Title, A
Loop %ArrayCount%
{
element := ArrayTime%A_Index%
Time = %A_WDay%%A_Hour%%A_Min%
msgbox %Time% , %element%
if (Time=%element%)
{
IfWinExist, Test.txt
{
WinActivate
Sleep 500
Send Hi{enter}
msgbox %Time% , %element%
Sleep 500
WinActivate, %Title%
}
}
}
Ok so the main issue is with this part:
if (Time=%element%)
I have also tried
if (%Time%=%element%)
if (A_WDay . A_Hour . A_Min=%element%)
And I think some other similar variations, the problem I'm getting is it's either always true, or always false, depending on how I have it written.
Inside the text file is a list like this:
10000
10700
11400
20400
21100
I add an extra line that has the current time for testing, and I added the msgbox to compare, and I can clearly see they're both the same when it doesn't work, or that they're different when it does. Sorry for such a basic question but I feel like I've really been trying for a long time and read everything I can on variables and IF statements, thanks for any help.
Also the point of it is I need it to go off every 7 hours starting at midnight on sunday, this is what I came up with, if there's maybe a completely better way in general I'd be happy to hear that too.
Try this:
if % Time = element
{
MsgBox, Equal!
}
As for the scheduling part, try running your script through Windows Task Scheduler (hit Windows+R, type taskschd.msc and press Enter). There are tutorials on the Internet explaining how to create new tasks.
With regard to timers, have a look at this as an example.
SetTimer, AlertType1, 60000
ToAlertType1:=1
ToAlertType2:=1
AlertType1:
;If A_WDay between 2 and 7 ; is day monday - sunday?
;{
If (A_Hour = 7 or A_Hour = 13)
{
If (ToAlertType1)
{
SoundBeep, 500, 500
ToAlertType2:=1
ToAlertType1:=0
MsgBox, 4096,%AppName%, Msg1.
Return
}
}
Else if (A_Hour = 21)
{
If (ToAlertType2)
{
SoundBeep, 500, 500
ToAlertType2:=0
ToAlertType1:=1
MsgBox, 4096,%AppName%, Msg2.
Return
}
}
;}
Return