Mouse Button as Hotkey works unreliable

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fisatec
Posts: 42
Joined: 26 Sep 2022, 07:31

Mouse Button as Hotkey works unreliable

Post by Fisatec » 07 Oct 2022, 04:50

Hi @all,
I need a simple script in which the middle Mouse Button is remapped to 1. Left Click and 2. Send CTRL+M:

Code: Select all

      MButton::
	  MouseClick, Left
	  Send, ^m
	  Return
In this Case, the Send, ^m does only work rarely. Sleep does not make any difference.

So I tried to use MButton to click left and MButton UP to Send CTRL+M instead, which also does not work reliable:

Code: Select all

      MButton::
	  MouseClick, Left
	  Return

      MButton UP::
	  Send, ^m
	  Return
Replacing the hotkey with any key instead of Mouse Button does make a huge difference. Everything works as intended then:

Code: Select all

      ^a::
	  MouseClick, Left
	  Send, ^m
	  Return
Using the app "X-Mouse Button Control" works as intended with same commands. So couldn't be the mouse itself.
What else could cause this kind of problem?

Kind regards
Fisatec

//EDIT:
Mousebutton does work reliable, but the shortcuts were not recognized. Workaround in my last post.
Last edited by Fisatec on 13 Oct 2022, 01:24, edited 1 time in total.

User avatar
mikeyww
Posts: 26884
Joined: 09 Sep 2014, 18:38

Re: Mouse Button as Hotkey works unreliable

Post by mikeyww » 07 Oct 2022, 06:00

Check :arrow: KeyHistory

Code: Select all

MButton Up::Send {LButton}^m
image221007-0700-001_cr.png
Key history
image221007-0700-001_cr.png (15.23 KiB) Viewed 870 times

Fisatec
Posts: 42
Joined: 26 Sep 2022, 07:31

Re: Mouse Button as Hotkey works unreliable

Post by Fisatec » 07 Oct 2022, 06:38

@mikeyww Thanks for your fast reply and your helpful hints.

Unfortunately the script does not work reliable for me. Changing the hotkey to CTRL+a e.g. does work reliable.
I uploaded both KeyHistory screenshots.

MButton:
KeyHistory MButton.jpg
KeyHistory MButton.jpg (19.63 KiB) Viewed 861 times


CTRL+a:
KeyHistory ^a.jpg
KeyHistory ^a.jpg (26.98 KiB) Viewed 862 times

User avatar
mikeyww
Posts: 26884
Joined: 09 Sep 2014, 18:38

Re: Mouse Button as Hotkey works unreliable

Post by mikeyww » 07 Oct 2022, 08:36

It looks about the same, but if you are using mouse utility software, it could conflict with AutoHotkey.

Fisatec
Posts: 42
Joined: 26 Sep 2022, 07:31

Re: Mouse Button as Hotkey works unreliable

Post by Fisatec » 07 Oct 2022, 11:26

While testing this scripts, the other app manipulating the Mouse Buttons is closed.

It's the same for LButton and RButton. It just works kind of randomly, while Keyboard hotkeys work great everytime :?:

User avatar
mikeyww
Posts: 26884
Joined: 09 Sep 2014, 18:38

Re: Mouse Button as Hotkey works unreliable

Post by mikeyww » 07 Oct 2022, 12:45

Sorry I have no explanation for you unless your target program responds to the mouse buttons differently. Others may have some other answers or suggestions here.

Fisatec
Posts: 42
Joined: 26 Sep 2022, 07:31

Re: Mouse Button as Hotkey works unreliable

Post by Fisatec » 10 Oct 2022, 07:42

I could not get it to work properly with ahk only, but I combined the ahk-Script with XMouse Button Control.

It's working for now.
In defined areas of a window, the MButton behaves like declared in XMouse App.

Code: Select all

#IfWinActive, AHK_exe inforCOM.exe

SetTimer, WatchCursor, 500
Return

WatchCursor:
CoordMode, Mouse, Window
MouseGetPos, xpos, ypos

MButton::

      if (xpos>250&&xpos<=1890) && (ypos>300&&ypos<=465){
      Send {LButton}^1
	  Sleep 50
	  Send {MButton}
	  }

      Else{ 
	  Send {LButton}^2
	  Sleep 50
	  Send {MButton}
	  }
	  
Return
CTRL+1 and CTRL+2 are Hotkeys used to switch between Layers in XMouse.

I have absolutely no idea, why previously posted codes won't work well for me.

Kind regards,
Fisatec

User avatar
mikeyww
Posts: 26884
Joined: 09 Sep 2014, 18:38

Re: Mouse Button as Hotkey works unreliable

Post by mikeyww » 10 Oct 2022, 08:54

When you tried the previous script, had you completely closed XMouse Button Control, so that its process was no longer running?

Fisatec
Posts: 42
Joined: 26 Sep 2022, 07:31

Re: Mouse Button as Hotkey works unreliable

Post by Fisatec » 11 Oct 2022, 00:00

@mikeyww Yes, XMouse Button Control was completely closed.

Kind regards
Fisatec

User avatar
mikeyww
Posts: 26884
Joined: 09 Sep 2014, 18:38

Re: Mouse Button as Hotkey works unreliable

Post by mikeyww » 11 Oct 2022, 06:41

OK. Thanks for the information.

Fisatec
Posts: 42
Joined: 26 Sep 2022, 07:31

Re: Mouse Button as Hotkey works unreliable

Post by Fisatec » 12 Oct 2022, 04:37

Hey @mikeyww,
I kinda solved my Problem.

Instead of using Shortcuts like CTRL+M, I bypassed them by using ALT+... to enter the praograms dropdown menus.
This works like intended and is absolutely reliable.

Code: Select all

#IfWinActive, AHK_exe inforCOM.exe

SetTimer, WatchCursor, 50
Return

WatchCursor:
CoordMode, Mouse, Window
MouseGetPos, xpos, ypos


MButton::
      if (xpos>250&&xpos<=1890) && (ypos>300&&ypos<=465){
	  Send {LButton}
	  Send {ALT}
      KeyWait, ALT
      Send v
	  KeyWait, v
      Send {ENTER}
	  KeyWait, ENTER
	  }

      Else{ 
	  Send {LButton}
	  Send {ALT}
      KeyWait, ALT
      Send v
	  KeyWait, v
	  Send {DOWN}
	  KeyWait, DOWN
      Send {ENTER}
	  KeyWait, ENTER
	  }	  
	  
Return
Not the way I initially wanted, but does its job and I don't need any other app.
Thank for your help.

Kind regards
Fisatec

Post Reply

Return to “Ask for Help (v1)”