Advertisement
sanek2k6

ScrollDiscord.ahk

Jun 4th, 2020
2,406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance Force
  2. #Persistent
  3.  
  4. ; constants
  5. discordTitleMatchingString := "ahk_exe Discord.exe"
  6. rdpTitleMatchingString := "ahk_class TscShellContainerClass"
  7. scriptReloadedId := "reloaded"
  8.  
  9. isFirstRunAfterReload := ((A_Args.Length() > 0) And (A_Args[1]=scriptReloadedId))
  10.  
  11.  
  12. SetTimer, ScrollDiscord, 500, 2
  13. SetTimer, SuspendOnRDPMaximized, 1000, 1
  14.  
  15. return
  16.  
  17.  
  18. ScrollDiscord:
  19.     WinGet, DiscordState, MinMax, %discordTitleMatchingString%
  20.  
  21.     ; if Discord windows is minimized, return
  22.     If (DiscordState = -1)
  23.         return
  24.    
  25.     ; if mouse is over the Discord window, return
  26.     if MouseIsOver(discordTitleMatchingString)
  27.         return
  28.            
  29.     ; if Discord window is active, return
  30.     if WinActive(discordTitleMatchingString)
  31.         return
  32.    
  33.     ControlFocus,, %discordTitleMatchingString%
  34.     Gosub, SendPageDown
  35.  
  36.     return
  37.  
  38.  
  39. SuspendOnRDPMaximized:
  40.     If WinActive(rdpTitleMatchingString) {
  41.         if isFirstRunAfterReload {
  42.             isFirstRunAfterReload := false
  43.             WinWaitNotActive, %rdpTitleMatchingString%
  44.             return
  45.         }
  46.  
  47.         WinGet, maxOrMin, MinMax, %rdpTitleMatchingString%
  48.         if (maxOrMin = 0) {
  49.             WinGetPos, PosX, PosY, WinWidth, WinHeight, %rdpTitleMatchingString%
  50.             if (PosY = 0) {  ; it is fully maximized
  51.                  Gosub, RestartScript
  52.             }
  53.         }
  54.     }
  55.     return
  56.    
  57.    
  58. SendPageDown:
  59.     PostMessage, 0x100, 0x22,,, %discordTitleMatchingString% ; 0x100 = WM_KEYDOWN, 0x22 = page down
  60.     Sleep, 50
  61.     PostMessage, 0x101, 0x22,,, %discordTitleMatchingString% ; 0x100 = WM_KEYUP, 0x22 = page down
  62.    
  63.     return
  64.  
  65.  
  66. RestartScript:
  67.     if A_IsCompiled
  68.         Run "%A_ScriptFullPath%" /restart "%scriptReloadedId%"
  69.     else
  70.         Run "%A_AhkPath%" /restart "%A_ScriptFullPath%" "%scriptReloadedId%"
  71.        
  72.     return
  73.    
  74.    
  75. MouseIsOver(vWinTitle:="", vWinText:="", vExcludeTitle:="", vExcludeText:="")
  76. {
  77.     MouseGetPos,,, hWnd
  78.     return WinExist(vWinTitle (vWinTitle=""?"":" ") "ahk_id " hWnd, vWinText, vExcludeTitle, vExcludeText)
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement