0

Recently I've been trying to rebind the 3-finger gestures of my Logitech Wireless Trackpad to switch between desktops in Windows 10. The code I used was the following:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
XButton1::SendInput {LCtrl down}{LWin down}{Right}{LCtrl up}{LWin up}
XButton2::SendInput {LCtrl down}{LWin down}{Left}{LCtrl up}{LWin up}
#F::Send {LWin down}{Tab}{LWin up}

However, when I press the buttons on my mouse I use for Browser_forward and Browser_Back, the mouse switches between desktops as well. Can you force AutoHotKey to only use the trackpad for it's gestures? If so, how?

GameShine
  • 1
  • 1

1 Answers1

1

You have two options here!

  1. You can exclude certain windows from activating your hotkey
  2. Make your hotkey only active on certain windows excluding all others

You can do this by using #IfWinActive #If WinActive IfWinActive WinGet, lots of options on Functions and Commands for this...

Since you mentioned desktop, I got curious how one would go about detecting if the desktop was Active, below is the result:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
$XButton1::
    If (IsDeskTopActive())
        SendInput {LCtrl down}{LWin down}{Right}{LCtrl up}{LWin up}
    Else 
        SendInput {XButton1}
Return

$XButton2::
If (IsDeskTopActive()) 
     SendInput {LCtrl down}{LWin down}{Left}{LCtrl up}{LWin up}
Else 
    SendInput {XButton2}
return

#F::Send {LWin down}{Tab}{LWin up}

IsDesktopActive() { ; Modified.. orignal by HotKeyIt
    MouseGetPos,,,win
    WinGetClass, class, ahk_id %win%
    If class in Progman,WorkerW
        Return True
    Return False
}
errorseven
  • 2,672
  • 2
  • 14
  • 20