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
Related
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 trying to reboot PC at specific hour when a click mouse loop is running. I used if + else conditions and when I try to run both pieces of code separately the script works but when put together only the mouse clicking loop is running while the timer process takes no effect. Any ideas what’s wrong?
^+f::
SetTimer, Chronos, 500
return
Chronos:
FormatTime, TimeToMeet,,HHmm
If (TimeToMeet = 2018)
{
Run, %comspec% /c shutdown -r -f -t 0
}
else
{
loop
{
MouseClick, Left, 787, 512, 1,0
Sleep 10000
}
}
Return
k::Pause
The loop statement never exits.
You're using a timer so I assume you want your code to be event driven. If that's the case, make the MouseClick part of a timer instead of a sleeping loop.
If you don't want to use events, put your shutdown clause inside of the loop
This clicks (787,512) every 10 seconds until 20:18, at which time it shuts the computer down
^+f::
SetTimer, Chronos, 500
return
Chronos:
loop
{
FormatTime, TimeToMeet,,HHmm
If (TimeToMeet = 2018)
{
Run, %comspec% /c shutdown -r -f -t 0
}
MouseClick, Left, 787, 512, 1,0
Sleep 10000
}
k::Pause
This clicks (787,512) every 10 seconds until 20:18, at which time it shuts the computer down
F2:: start()
F3:: stop()
start()
{
global running := 1
while running {
FormatTime TimeToMeet,,HHmm
if (TimeToMeet = 1349 )
Shutdown 13
click 787,512
sleep 10000
}
}
stop()
{
global running := 0
}
Iv been recently interested in developing a way to measure the times between my mouse clicks for research however im unsure what functions autohotkey has available to help with this. I firstly tried to get a measure of the exact time using :
FormatTime, ssnow, %A_Now%, ss
The problem with this was that subtracting one time from another is apparently impossible in autohotkey according to some forums i have searched and the result when testing also produced an empty value.
Is there a way to initiate a counter when the left button is down and then stop the timer when the button is released?
Here is the code I have been working on:
clickTime := 0
lastClick := 0
~LButton::
FormatTime, ssnow, %A_THEN%, ss
lastClick=%A_THEN%
~LButton Up::
FormatTime, ssnow, %A_Now%, ss
clickTime=%A_Now%
MsgBox (%clickTime% - %lastClick% )
Try:
~LButton::
StartTime := A_TickCount
While(GetKeyState("LButton", "P"))
continue
ToolTip % A_TickCount - StartTime
return
or:
~LButton::
StartTime := A_TickCount
keywait, LButton, L
ToolTip % A_TickCount - StartTime
return
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.
I was hoping to reset the tooltip with the AHK code below. While the msgbox is executed, the tool tip is not reset.
f9::
Loop
{
MouseGetPos, X, Y
PixelGetColor, color, X, Y
ToolTip, %color%`n%X%`n%Y%, X+10, Y-150
sleep 100
}
Exit
Escape::
ToolTip
MsgBox
Exit
Passing an empty value to the Tooltip command just removes the tooltip. I'm not sure what you mean by reset but If you mean to stop the loop, you can set a flag and check it with a While loop.
f9::
on := true
While on
{
MouseGetPos, X, Y
PixelGetColor, color, X, Y
ToolTip, %color%`n%X%`n%Y%, X+10, Y-150
sleep 100
}
tooltip
Exit
Escape::
on := false
MsgBox
Exit