Logitech MX Master Mouse... Again. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Logitech MX Master Mouse... Again.

27 Jun 2019, 04:34

I'm reluctant to post this since the topic has been covered many times before, but I can't find a solution to my particular problem. I'm trying to remap the extra keys on my MX Master mouse without having to use the supplied Logitech software. No reason to have yet another program always running, always using my internet connection, and always transmitting personal data, if I don't have too.

Most of it is easy. The default functions, without the Logitech software running are;
Forward Button = XButton1
Back Button = XButton2
Thumb wheel = WheelLeft/WheelRight

However, the gesture button's default seems to be a variant of alt/tab. But when I try to use "!Tab::" as a hotkey the script reacts to the keyboard but the mouse still brings up the alt/tab window. I've tried using AHKHID, to find what the buttons sends, but it seems to be outdated and no longer working. Edit: AHKHID is working but I'm still not able to find the button.

Any ideas on being able to remap the gesture button without running the Logitech software? Thanks

Code: Select all

!Tab::
MsgBox, Yup
Return
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Logitech MX Master Mouse... Again.  Topic is solved

27 Jun 2019, 05:48

Success!!!!!
Once I figured out the AHKHID wasn't working due to user error I was able to use it to find the mouse button.

Turns out, that button is seen as another keyboard. The keys it send is Control+Alt+Tab. AHKHID told me it sends special keys VK17 and VK18, when I figured out those were Control and Alt I realized the key combination.

Code: Select all

^!Tab::
MsgBox, You pressed the MX Master Mouse gesture key.
Return
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Logitech MX Master Mouse... Again.

27 Jun 2019, 06:10

For anyone else who has questions on this mouse, here is a list of the default buttons when the Logitech software is not running.

Code: Select all

XButton1:: 
MsgBox, You pressed browser back.
Return

XButton2:: 
MsgBox, You pressed browser forward.
Return

WheelLeft:: 
MsgBox, You turned the horizontal wheel up.
Return

WheelRight:: 
MsgBox, You turned the horizontal wheel down.
Return

^!Tab:: 
MsgBox, You pressed the gesture button.
Return
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Logitech MX Master Mouse... Again.

27 Oct 2020, 15:41

Thanks, this is useful.
brigcam
Posts: 1
Joined: 23 Apr 2021, 13:22

Re: Logitech MX Master Mouse... Again.

23 Apr 2021, 13:40

thank you very much! maybe it's possible to capture also the "switch" button? the one that switches between the "step" and "fast" mode for the wheel, it can be remapped with logitech options
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Logitech MX Master Mouse... Again.

23 Apr 2021, 14:50

@brigcam Yes that is possible. I re-mapped the middle button by using the Logitech software, then used ahk to perform more complex actions when the middle button is pushed.
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Logitech MX Master Mouse... Again.

25 Apr 2021, 19:43

brigcam wrote:
23 Apr 2021, 13:40
thank you very much! maybe it's possible to capture also the "switch" button? the one that switches between the "step" and "fast" mode for the wheel, it can be remapped with logitech options
Yes, I was able to use the old AHKHID scripts from "The Good" to find and use this button on the mouse without the Logitech software running. You will need the AHKHID Library in your library folder or directly called by the script. It's a complex script but the mouse settings should be the same for everyone so, theoretically, you should only need to add your command to the bottom.

The button's label is simply "4:" and it must be used as a label, not a hotkey. I've added a prefix and now the glable is "Default_4" which should trigger no matter what window is active. If you want to make the button context sensitive, i.e. have a different function for different windows, you can use my old script Other HID Info to create the labels and associations.

Code: Select all

#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir%  
#SingleInstance, Force

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AHKHID_UseConstants() ;If AHKHID.ahk is in your library use this line as is.
; If you want to call the script from the directory your script is in or a particular directory
; you would use something like this.
;#Include C:\enter your directory path here\AHKHID.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Create GUI to receive messages
Gui, +LastFound
hGui := WinExist()

;Intercept WM_INPUT messages
WM_INPUT := 0xFF
OnMessage(WM_INPUT, "InputMsg")

;Register Remote Control with RIDEV_INPUTSINK (so that data is received even in the background)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
r := AHKHID_Register(65280, 2, hGui, RIDEV_INPUTSINK) ;Replace 65468 with your device's Usage
;Page number and 137 with you device's Usage number.  If your device has more than 1 Usage Page/Usage
;Make a copy of this line for each one.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Prefix loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Replace the prefixes with the prefixes you used to make your g-label.  These must match exactly.
Loop {
    Sleep 1000
    If WinActive("ahk_class QWidget") Or WinActive("ahk_class VLC DirectX")
        sPrefix := "VLC_"
    Else If WinActive("ahk_class Winamp v1.x") Or WinActive("ahk_class Winamp Video")
        sPrefix := "Winamp_"
    Else If WinActive("ahk_class MediaPlayerClassicW")
        sPrefix := "MPC_"
    Else sPrefix := "Default_" ;If you're using labels without prefixes delete the word "Default".
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}

Return


InputMsg(wParam, lParam) {
    Local devh, iKey, sLabel

    Critical

    ;Get handle of device
    devh := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)

    ;Check for error
    If (devh <> -1) ;Check that it is my HP remote
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        And (AHKHID_GetDevInfo(devh, DI_DEVTYPE, True) = RIM_TYPEHID)
        And (AHKHID_GetDevInfo(devh, DI_HID_VENDORID, True) = 1133) ;Replace these three
        And (AHKHID_GetDevInfo(devh, DI_HID_PRODUCTID, True) = 50475) ;numbers with your
        And (AHKHID_GetDevInfo(devh, DI_HID_VERSIONNUMBER, True) = 9223) { ;devices numbers.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        ;Get data
        iKey := AHKHID_GetInputData(lParam, uData)

        ;Check for error
        If (iKey <> -1) {

            ;Get keycode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            iKey := NumGet(uData, 1, "UChar") ;If you had to change "+#" to something other
			                                  ; than 1 it must be changed here too.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;Call the appropriate sub if it exists
            sLabel := sPrefix iKey
			If IsLabel(sLabel)
                Gosub, %sLabel%
        }
    }
}
; From here down replace these with your g-labels and commands.  These are "TheGoods" examples.
; Remeber the word "Default_" is valid for a prefix and will be active any time an application
; for one of your other label is not in focus.  The first example can be used to open VLC Media Player
; then the "VLC_" labels can control it.

Default_4:
MsgBox, MX Master Mouse
Return
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Logitech MX Master Mouse... Again.

25 Apr 2021, 21:40

@x32 awesome find! Thanks for sharing AHKHID, seems very useful. 👍
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Logitech MX Master Mouse... Again.

25 Apr 2021, 23:25

SirSocks wrote:
25 Apr 2021, 21:40
@x32 awesome find! Thanks for sharing AHKHID, seems very useful. 👍
No problem. I've been using AHKHID since I started with AHK. I wrote an automation program, or you might call it a script writer, using AHKHID as one of the main components. It's a program that I use constantly when I'm on a computer, Easy Automation AHK. It could be used to capture the input of the MX mouse without having to write any scripts.
chaoscreater
Posts: 60
Joined: 12 Sep 2019, 21:15

Re: Logitech MX Master Mouse... Again.

24 May 2021, 18:44

Hi, I wonder if you can help me.

I have a MX Master 3 and I would like to remap the thumb scroll wheel. If I double click on an existing Autohotkey script in the right traybar and view the "Key history and script info", I can see that when I use the scroll wheel, it shows either Media_Next or Media_Prev. This seems correct, because in Logitech Options, I have mapped the scroll wheel to skip to next/prev track.

How can I map this using AHK instead? I've tried using that AHKHID thing and I can get it to launch, but I don't understand the options.
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Logitech MX Master Mouse... Again.

25 May 2021, 02:43

On my MX2 (I think it's 2, can't remember) the wheel is standard and can be found in the AHK key list. I suspect that it may be the same for you but the Logitech software is conflicting. AHK may be intercepting the wheel events before the Logitach software can assign the Media_Prev/Next keystrokes to it. I never installed Logitech software on my system so I can't say for sure. Here is the section from my script.

Code: Select all

WheelLeft:: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FF
IfWinExist, ahk_class Qt5QWindowIcon
	{
	VLCHTTP2_JumpForward(5)
	Return
	}
Send, {Right}
Return
WheelRight:: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RW
IfWinExist, ahk_class Qt5QWindowIcon
	{
	VLCHTTP2_JumpBackward(5)
	Return
	}
Send, {Left}
Return
Edit: If your mouse is actually sending Media_Next/Prev then use those as hotkeys.

Code: Select all

Media_Next::
MsgBox, Next
Return

Media_Prev::
MsgBox, Prev
Return
JanP
Posts: 3
Joined: 13 Jun 2021, 10:21

Re: Logitech MX Master Mouse... Again.

13 Jun 2021, 10:31

Hello! This has been extremely useful! I am trying to map the Task View to the thumb button of my logitech mx master 2 mouse.
I have successfylly tested that ^!Tab really shows the message box. I have also tried mapping #Tab to MButton and it has worked just fine.
The problem is when I try to make the two work together. :crazy:

I have tried both

Code: Select all

^!Tab:: #Tab
and

Code: Select all

^!Tab::
Send, {Blind}#{Tab}
Return
But without any luck. I would be grateful for any suggestions!!
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Logitech MX Master Mouse... Again.

13 Jun 2021, 14:07

Sorry but I really don't understand what you are trying to do there. Since you're needing help with the code, and not specifically with the mouse, perhaps you should start your own thread in the help section so some more knowledgeable people might see it.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: inseption86, jaka1, metallizer, rc76, Rohwedder and 314 guests