Hi,
I'd like to make a macro that triggers whenever I've held down the left mouse button for a certain period of time. Is there a way I can make that trigger in Macro Scheduler?
Can I make this trigger somehow?
Moderators: Dorian (MJT support), JRL
You can.
Your mouse has to be stationary for the script to work.
1. Move your mouse to the area you want to click
2. Press your left mouse button
3. Do not move your mouse
Your mouse has to be stationary for the script to work.
1. Move your mouse to the area you want to click
2. Press your left mouse button
3. Do not move your mouse
Code: Select all
OnEvent>KEY_DOWN,VK1,0,MButtonPressed
//Enter sec to wait
Let>SecToWait=2
Let>LeftButtonPressed=False
Label>ActionLoop
Wait>0.01
IF>LeftButtonPressed=True
//Cursor has to be stationary for the timer to work
//Compare Cursor position against position A
GetCursorPos>XPosB,YPosB
IF>{(%XPosB%=%XPosA%)AND(%YPosB%=%YPosA%)}
Timer>EndTimer
Let>SecElapsed={(%EndTimer%-%StartTimer%)/1000}
IF>SecElapsed>%SecToWait%
//Do something if the mouse button has been
//pressed for more than X seconds.
GoSub>DoSomething
ENDIF
ELSE
Let>LeftButtonPressed=False
ENDIF
ENDIF
Goto>ActionLoop
SRT>DoSomething
MDL>Left Mouse button pressed for %SecElapsed% sec.
Let>LeftButtonPressed=False
END>DoSomething
SRT>MButtonPressed
IF>LeftButtonPressed=False
Let>LeftButtonPressed=True
Timer>StartTimer
//Save mouse position A
GetCursorPos>XPosA,YPosA
ENDIF
END>MButtonPressed
Try this one.
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Left = 176
Top = 80
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 63
ClientWidth = 184
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 8
Top = 8
Width = 32
Height = 13
Caption = 'Label1'
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,,OnClose,ExitScript
Show>Dialog1
Let>MButtonPressed=False
Let>Sec_Elapsed=0
Label>Loop
Wait>0.01
LibFunc>User32,GetKeyState,KEY_STATE,1
IF>{(%KEY_STATE%>65400)}
IF>MButtonPressed=False
Let>MButtonPressed=True
Timer>StartTimer
ENDIF
Timer>EndTimer
Let>Sec_Elapsed={(%EndTimer%-%StartTimer%)/1000}
SetDialogProperty>Dialog1,Label1,Caption,Mouse Down%CRLF%Mouse State: %KEY_STATE%%CRLF%Elapsed: %Sec_Elapsed%
ELSE
SetDialogProperty>Dialog1,Label1,Caption,Mouse UP%CRLF%Mouse State: %KEY_STATE%%CRLF%Elapsed: %Sec_Elapsed%
Let>MButtonPressed=False
ENDIF
Goto>Loop
SRT>ExitScript
Exit>1
END>ExitScript