Advertisement
Lorenzo501

Left+Right Click File To Open in GitHub Web Editor.ahk

Mar 26th, 2024 (edited)
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Requires AutoHotkey 2.0
  2. A_CoordModeMouse := "Screen"
  3. SetDefaultMouseSpeed(0)
  4.  
  5. #HotIf (WinActive("ahk_exe explorer.exe"))
  6. RButton::
  7. {
  8.     static EVENT_OBJECT_CREATE := 0x8000
  9.  
  10.     Critical(-1)
  11.  
  12.     while (GetKeyState("RButton", "P"))
  13.     {
  14.         if (KeyWait("LButton", "D T0.05"))
  15.         {
  16.             HotIf()
  17.             Hotkey("LButton", (*) => 0, "On")
  18.             Hotkey("RButton", (*) => 0, "On")
  19.             Hotkey("LButton up", (*) => 0, "On")
  20.             DllCall("SetWinEventHook", "UInt", EVENT_OBJECT_CREATE, "UInt", EVENT_OBJECT_CREATE, "Ptr", 0, "Ptr", CallbackCreate(HandleDragImageEvent), "UInt", 0, "UInt", 0, "UInt", 0)
  21.             MouseGetPos(&previousCursorX, &previousCursorY)
  22.             SystemCursor("Toggle")
  23.             Send("{Click " previousCursorX + 5 " " previousCursorY " 0}")
  24.             Sleep(10)
  25.             Send("{Click " previousCursorX - 5 " " previousCursorY " 0}")
  26.             Sleep(10)
  27.             Send("{Click " previousCursorX " " previousCursorY " 0}")
  28.             SystemCursor("Toggle")
  29.             Run("chrome.exe https://github.dev/ --start-maximized --disable-features=GlobalMediaControls")
  30.             Sleep(100)
  31.             WinWaitActive("Visual Studio")
  32.             MouseGetPos(&previousCursorX, &previousCursorY)
  33.             SystemCursor("Toggle")
  34.             Send("{Click " A_ScreenWidth / 2 " " A_ScreenHeight / 2 " 0}")
  35.             Sleep(50)
  36.             Send("{Click " A_ScreenWidth / 2 " " A_ScreenHeight / 2 " U}")
  37.             Send("{Click " previousCursorX " " previousCursorY " 0}")
  38.             SystemCursor("Toggle")
  39.             Hotkey("LButton", "Off")
  40.             Hotkey("RButton", "Off")
  41.             Hotkey("LButton up", "Off")
  42.  
  43.             return
  44.         }
  45.     }
  46.  
  47.     Send("{RButton}")
  48. }
  49.  
  50. SystemCursor(cmd) ; cmd = "Show|Hide|Toggle|Reload"
  51. {
  52.     static visible := true, c := Map()
  53.     static sys_cursors := [32512, 32513, 32514, 32515, 32516, 32642, 32643, 32644, 32645, 32646, 32648, 32649, 32650]
  54.  
  55.     if (cmd = "Reload" || !c.Count) ; Reload when requested or at first call
  56.     {
  57.         for (i, id in sys_cursors)
  58.         {
  59.             h_cursor  := DllCall("LoadCursor", "Ptr", 0, "Ptr", id)
  60.             h_default := DllCall("CopyImage", "Ptr", h_cursor, "UInt", 2, "Int", 0, "Int", 0, "UInt", 0)
  61.             h_blank   := DllCall("CreateCursor", "Ptr", 0, "Int", 0, "Int", 0, "Int", 32, "Int", 32, "Ptr", Buffer(32 * 4, 0xFF), "Ptr", Buffer(32 * 4, 0))
  62.             c[id] := {Default: h_default, Blank: h_blank}
  63.         }
  64.     }
  65.  
  66.     switch (cmd)
  67.     {
  68.         case "Show": visible := true
  69.         case "Hide": visible := false
  70.         case "Toggle": visible := !visible
  71.         default: return
  72.     }
  73.  
  74.     for (id, handles in c)
  75.     {
  76.         h_cursor := DllCall("CopyImage", "Ptr", visible ? handles.Default : handles.Blank, "UInt", 2, "Int", 0, "Int", 0, "UInt", 0)
  77.         DllCall("SetSystemCursor", "Ptr", h_cursor, "UInt", id)
  78.     }
  79. }
  80.  
  81. HandleDragImageEvent(hWinEventHook, event, hWnd, *)
  82. {
  83.     static hiddenImagesAmount := 0
  84.  
  85.     try
  86.         if (WinGetClass(hWnd) = "SysDragImage") ; Both explorer.exe and chrome.exe have one
  87.         {
  88.             WinKill(hWnd)
  89.  
  90.             if (++hiddenImagesAmount = 2)
  91.                 DllCall("UnhookWinEvent", "Ptr", hWinEventHook)
  92.         {
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement