Can I make this trigger somehow?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Bontrager
Newbie
Posts: 2
Joined: Tue Nov 19, 2013 1:10 am

Can I make this trigger somehow?

Post by Bontrager » Tue Nov 19, 2013 1:14 am

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?

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Tue Nov 19, 2013 4:29 pm

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

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

Bontrager
Newbie
Posts: 2
Joined: Tue Nov 19, 2013 1:10 am

Post by Bontrager » Wed Nov 20, 2013 3:49 am

Ooh, thanks, but I guess I should have posted that I have to be able to move the mouse as well :(

Thanks anyway!

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Thu Nov 21, 2013 3:32 pm

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

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts