Hacker News new | past | comments | ask | show | jobs | submit login

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
    }



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: