How to tell which mouse button is used

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
OldGeek
Junior Coder
Posts: 23
Joined: Thu Oct 30, 2014 11:49 am
Location: Upstate NY, USA

How to tell which mouse button is used

Post by OldGeek » Mon May 08, 2023 1:30 pm

I downloaded a script (from Macro Scheduler website) called Mouse Tester, but it is not working. I think the part that is broken is when it is trying to tell which mouse button (Left, Right, Middle) is doing the click. I think I'm following the code. It is using two events:
AddDialogHandler>Dialog1,MSButton1,OnMouseDown,MDOWN
AddDialogHandler>Dialog1,MSButton1,OnMouseUp,MUP

From there is goes to the two subroutines (MDOWN or MUP)

SRT>DBUTCHECK
Let>mdbutton=%MDOWN_BUTTON%
SetDialogProperty>Dialog1,Edit1,Text,x=%mx% y=%my% button val: %mdbutton%
IF>mdbutton=0
LET>dbutt=Left
ENDIF
IF>mdbutton=8386
LET>dbutt=Right
ENDIF
IF>mdbutton=32
LET>dbutt=Middle
ENDIF
END>DBUTCHECK

But the variable %NDOWN_BUTTON% has nothing stored in it. The script may be from an old version of Macro Scheduler, I'm not sure. So how can I tell which mouse button has been used to click on something?

Thank You
I'm a beginner
MS v15 | Windows 11 Pro | NY, USA

OldGeek
Junior Coder
Posts: 23
Joined: Thu Oct 30, 2014 11:49 am
Location: Upstate NY, USA

Re: How to tell which mouse button is used

Post by OldGeek » Mon May 08, 2023 1:58 pm

I found the original post here: viewtopic.php?p=29092
MS v15 | Windows 11 Pro | NY, USA

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1350
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: How to tell which mouse button is used

Post by Dorian (MJT support) » Mon May 08, 2023 2:37 pm

If you temporarily add a MessageModal you can see what the corresponding values are when you click :

Code: Select all

  Let>mdbutton=%MDOWN_BUTTON%
  MessageModal>mdbutton
For me, a right-click was 1. So I changed 8386 to 1 :

Code: Select all

 IF>mdbutton=1
    LET>dbutt=Right 
  ENDIF
Left click was blank :

Code: Select all

IF>mdbutton=
    LET>dbutt=Left  
  ENDIF
Make sure to change for both down and up.

..and I don't have a middle button to test with. :)
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1350
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: How to tell which mouse button is used

Post by Dorian (MJT support) » Mon May 08, 2023 2:57 pm

Of course it's worth pointing out you can do this with an OnEvent. Be careful to include an exit routine (As I have here) otherwise you'll just trigger the SRT every time you try to press Stop.

Code: Select all

onevent>KEY_DOWN,VK1,0,LMB
onevent>KEY_DOWN,VK2,0,RMB


//Pseudo Script (20 second loop)
let>pointlessloop=0
repeat>pointlessloop
  Let>pointlessloop=pointlessloop+1
  Wait>1
Until>pointlessloop,20

srt>LMB
  mdl>left mouse
  ask>Exit?,AskExit
  If>AskExit=YES
    exit
  Endif
END>LMB

srt>RMB
  mdl>right mouse
    ask>Exit?,AskExit
  If>AskExit=YES
    exit
  Endif
END>RMB
Yes, we have a Custom Scripting Service. Message me or go here

OldGeek
Junior Coder
Posts: 23
Joined: Thu Oct 30, 2014 11:49 am
Location: Upstate NY, USA

Re: How to tell which mouse button is used

Post by OldGeek » Tue May 09, 2023 11:55 am

Thank you for your help. I will study both.
MS v15 | Windows 11 Pro | NY, USA

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