Advertisement
Doug4347

Click on an inactive window

Dec 10th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; 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. SetTitleMatchMode, 2
  6.  
  7. SettingsFile = Settings.ini
  8. Errorz = Error
  9.  
  10. Menu, Tray, NoStandard
  11. Menu, Standards, Standard
  12. Menu, Script, Add, Change Window, ChangeWindow
  13. Menu, Script, Add, Change Hotkey, ChangeHotkey
  14. Menu, Tray, Add, Script, :Script
  15. Menu, Tray, Add, Standards, :Standards
  16.  
  17. IniRead, XPos, %SettingsFile%, Mouse, XPos, -1
  18. IniRead, YPos, %SettingsFile%, Mouse, YPos, -1
  19. IniRead, Window, %SettingsFile%, Window, Name, -1
  20. IniRead, CurrentHotkey, %SettingsFile%, Hotkeys, SingleClick, -1
  21.  
  22. If (XPos < 0) or (YPos < 0) or (Window = -1)
  23.     Gosub, ChangeWindow
  24. If CurrentHotkey = -1
  25.     {
  26.         Gosub, ChangeHotkey
  27.         NewHotkey:=True
  28.     }
  29. If not NewHotkey
  30.     Hotkey, %CurrentHotkey%, SingleClick, On
  31. NewHotkey:=False
  32. HotkeysActive:=True
  33. Return
  34.  
  35. SingleClick:
  36.     IniRead, XPos, %SettingsFile%, Mouse, XPos, -1
  37.     IniRead, YPos, %SettingsFile%, Mouse, YPos, -1
  38.     IniRead, Window, %SettingsFile%, Window, Name, -1
  39.     If (XPos < 0) or (YPos < 0) or (Window = -1)
  40.         SoundBeep
  41.     Else
  42.         ControlClick, X%XPos% Y%YPos%, %Window%,,, 1
  43. Return
  44.  
  45. ChangeWindow:
  46.     InputBox, WindowNew,, Please enter all or part of the window's name.
  47.     Gosub, SplashWinMove
  48.     SetTimer, SplashWin, 0
  49.     SetTimer, SplashWin, On
  50.     KeyWait, LButton, Down
  51.     MouseGetPos, XPosNew, YPosNew
  52.     IniWrite, %XPosNew%, %SettingsFile%, Mouse, XPos
  53.     IniWrite, %YPosNew%, %SettingsFile%, Mouse, YPos
  54.     IniWrite, %WindowNew%, %SettingsFile%, Window, Name
  55.     SetTimer, SplashWin, Off
  56.     SplashImage, Off
  57.     MsgBox, Done!
  58. Return
  59.  
  60. SplashWin:
  61.     MouseGetPos, XPosSplash, YPosSplash
  62.     If (XPosSplash < 325) and (YPosSplash < 115)
  63.         {
  64.             XSplash:=330
  65.             YSplash:=120
  66.             SplashMoved:=True
  67.         }
  68.     Else
  69.         {
  70.             XSplash:=0
  71.             YSplash:=0
  72.             SplashMoved:=False
  73.         }
  74.     If SplashMoved and not SplashAlreadyMoved
  75.         {
  76.             GoSub, SplashWinMove
  77.             SplashAlreadyMoved:=True
  78.         }
  79.     If not SplashMoved and SplashAlreadyMoved
  80.         {
  81.             GoSub, SplashWinMove
  82.             SplashAlreadyMoved:=False
  83.         }
  84. Return
  85.  
  86. SplashWinMove:
  87.     SplashImage,, x%XSplash% y%YSplash%, Please click on the button you would like to select.
  88. Return
  89.  
  90. ChangeHotkey:
  91.     Gui, Add, Text, w300, Please select the box below and press any key/combonation of keys and then submit your input.
  92.     Gui, Add, Hotkey, vChosenHotkey
  93.     Gui, Add, Button, gSubmitHotkey, Submit
  94.     Gui, Show
  95. Return
  96.  
  97. SubmitHotkey:
  98.     Gui, Submit, NoHide
  99.     If not ChosenHotkey
  100.         {
  101.             MsgBox, 16,, Please enter a valid hotkey.
  102.             Return
  103.         }
  104.     Gui, Destroy
  105.     IniRead, CurrentHotkey, %SettingsFile%, Hotkeys, SingleClick, -1
  106.     If Hotkey = -1
  107.         Hotkey, %CurrentHotkey%, SingleClick, Off
  108.     IniWrite, %ChosenHotkey%, %SettingsFile%, Hotkeys, SingleClick
  109.     Hotkey, %ChosenHotkey%, SingleClick, On
  110.     MsgBox, 64,, Success!
  111. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement