0
votes

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
1

1 Answers

0
votes

My idea:

  1. 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.
  2. 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