Hacker News new | ask | show | jobs
by RonaldDump 542 days ago
Their best feature - and the one thing that I have most missed for years after moving to Linux - is automatically changing the active mouse profile based on the focused application.

It's so powerful. Any custom buttons for any program, without ever having to think about it. On Linux, without it, I'm stuck manually cycling through the 3 on-board profiles.

1 comments

I use Autohotkey in Windows to achieve that, because I got sick of Logitech fairly regularly misdetecting the current application (when it does that, you have to focus a different app and then try again).

I just get the mouse to always use the same onboard profile and send the higher F-keys that aren't on the keyboard (F13-F24), and ahk detects those and does whatever crazy stuff I can think up. I even have long-press/short-press for some buttons set up. Works great.

There must be a way to do something similar in Linux.

Do you have a specific script you like?
Here's a skeleton of what I use:

    #Requires AutoHotkey v2.0
    #SingleInstance force
    
    MsgBox(A_ScriptName " started",, "T0.5")
    
    SendLevel 1 ; allows triggering of hotkeys and hotstrings of another script, which normally would not be the case
    
    LongPress := 0.2 ; 200ms
    
    F18::{ ; first pointer button
     Switch WinGetProcessName("A") {
      Case "firefox.exe" :
       Send "+{F3}" ; Shift-F3 - Find previous
      Case "vlc.exe" :
       Send "PgUp"
      Default:
       NoFunctionDefined(A_ThisHotkey)
     }
     return
    }
    
    F20::{ ; third pointer button
     activeapp := WinGetProcessName("A")
     Switch activeapp {
      Case "vlc.exe" :
       Send "s"
      Default:
     }
     if (activeapp = "firefox.exe") {
      waitvar := (KeyWait(A_ThisHotkey, "T" LongPress)) ; waits LongPress seconds maximally for F20 to be released
      if waitvar {
       ; Short press action
       Send "{F24}"
      }
      else {
       ; Long press action
       Send "{F5}" ; F5 - reload tab
      }
      KeyWait A_ThisHotkey  ; waits for F20 to be released (avoids key repeat from retriggering)
     } else {
      Send "{F24}"
     }
     return
    }
    
    NoFunctionDefined(hotkey)
    {
        Tooltip("No function defined for " . hotkey "`nActive app is " WinGetProcessName("A"))
     SetTimer () => ToolTip(), -2000
     return
    }
    
    ; --- Shift-Media_Play_Pause will Reload this script ---
    ~+Media_Play_Pause::{
        MsgBox(A_ScriptName " Reloading...",, "T0.5")
        Reload
        Sleep 1000 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
        if MsgBox("The script could not be reloaded. Would you like to open it for editing?","Reload", "YesNo") = "Yes"
            Edit
        return
    }