SHARE
TWEET

AHK example

CleverSnake Jan 26th, 2020 550 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Env  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5.  
  6. ;MsgBox, 4,, Would you like to continue?
  7. ;IfMsgBox, No
  8. ;    return  ; If No, stop the code from going further.
  9. ;MsgBox, You pressed YES.  ; Otherwise, the user picked yes.
  10.  
  11. ; /*
  12. ;  * SendMessageTimeout values
  13. ;
  14. ; #define SMTO_NORMAL         0x0000
  15. ; #define SMTO_BLOCK          0x0001
  16. ; #define SMTO_ABORTIFHUNG    0x0002
  17. ; #if(WINVER >= 0x0500)
  18. ; #define SMTO_NOTIMEOUTIFNOTHUNG 0x0008
  19. ; #endif /* WINVER >= 0x0500 */
  20. ; #endif /* !NONCMESSAGES */
  21. ;
  22. ;
  23. ; SendMessageTimeout(
  24. ;     __in HWND hWnd,
  25. ;     __in UINT Msg,
  26. ;     __in WPARAM wParam,
  27. ;     __in LPARAM lParam,
  28. ;     __in UINT fuFlags,
  29. ;     __in UINT uTimeout,
  30. ;     __out_opt PDWORD_PTR lpdwResult);
  31. ;     */
  32.  
  33. CheckIfResponding(ProcessIdentifier) {
  34.     NR_temp =0 ; init
  35.     TimeOut = 100 ; milliseconds to wait before deciding it is not responding - 100 ms seems reliable under 100% usage
  36.     ; WM_NULL =0x0000
  37.     ; SMTO_ABORTIFHUNG =0x0002
  38.     WinGet, wid, ID, %ProcessIdentifier% ; retrieve the ID of a window to check
  39.     Responding := DllCall("SendMessageTimeout", "UInt", wid, "UInt", 0x0000, "Int", 0, "Int", 0, "UInt", 0x0002, "UInt", TimeOut, "UInt *", NR_temp)
  40.     return %Responding%
  41.     ;~ If Responding = 1 ; 1= responding, 0 = Not Responding
  42.       ;~ Msgbox, Responding
  43.     ;~ Else
  44.       ;~ Msgbox, Not Responding
  45. }
  46.  
  47.  
  48. F7::
  49.     Processname=discord.exe
  50.     Process, Exist, %Processname%
  51.  
  52.     if !ErrorLevel
  53.     {
  54.         MsgBox, % "Process " Processname " does not exists"
  55.         return
  56.     }
  57.  
  58.     pid:= ErrorLevel
  59.     discord := % "ahk_pid " pid
  60.     IfWinNotActive, %discord%
  61.     {
  62.         WinActivate, %discord%
  63.         WinWaitActive, %discord%
  64.     }
  65.     WinMaximize
  66.  
  67.     ;Send {Click, 220, 1016}
  68.     WinGetTitle, WindowTitle, %discord%
  69.     ;~ MsgBox, %WindowTitle%
  70.     ControlClick, X220 Y1016, %WindowTitle%
  71.     return
  72.    
  73. F6::
  74.     MsgBox, %A_Cursor%
  75.     WinGet, pid, PID, A
  76.     WinGet, pname, ProcessName, A
  77.     MsgBox, %pid% %pname%
  78.     app := % "ahk_pid " pid
  79.     WindowStatus := CheckIfResponding(app)
  80.     If WindowStatus = 1
  81.         MsgBox, Responding
  82.     Else
  83.         MsgBox, Not responding
  84.     return
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top