Advertisement
realslacker

HotKey Capture Script

Mar 15th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.58 KB | None | 0 0
  1. ; to exit this script right click the icon in the system tray
  2.  
  3. ; title of the window you want to capture shortcuts in
  4. $WindowTitle        = "Notepad"
  5.  
  6. ; visible text in window to help differentiate windows (optional)
  7. $WindowText         = ""
  8.  
  9. ; number of buttons defined below
  10. $NumberOfButtons    = 5
  11.  
  12. ; example button definition, the function can do any action - in this case making a message box and left clicking at coordinates 300 x 300
  13. $Button1_Capture    = "a"
  14. Func Button1_Click()
  15.     MsgBox(0,"","Button 1 Clicked")
  16.     MouseClick("left", 300, 300, 1, 0)
  17. EndFunc
  18.  
  19. $Button2_Capture    = "b"
  20. Func Button2_Click()
  21.     MsgBox(0,"","Button 2 Clicked")
  22.     MouseClick("left", 400, 400, 1, 0)
  23. EndFunc
  24.  
  25. $Button3_Capture    = "c"
  26. Func Button3_Click()
  27.     MsgBox(0,"","Button 3 Clicked")
  28.     MouseClick("left", 500, 500, 1, 0)
  29. EndFunc
  30.  
  31. $Button4_Capture    = "d"
  32. Func Button4_Click()
  33.     MsgBox(0,"","Button 4 Clicked")
  34.     MouseClick("left", 600, 600, 1, 0)
  35. EndFunc
  36.  
  37. $Button5_Capture    = "e"
  38. Func Button5_Click()
  39.     MsgBox(0,"","Button 5 Clicked")
  40.     MouseClick("left", 700, 700, 1, 0)
  41. EndFunc
  42.  
  43. ; === END DEFS ===
  44.  
  45. Opt("WinTitleMatchMode", 2) ; makes title string match anywhere in the title (vs. starting at the left)
  46.  
  47. While 1
  48.  
  49.     ; if window is active map hot keys
  50.     If WinActive($WindowTitle, $WindowText) Then
  51.  
  52.         For $i = 1 To $NumberOfButtons
  53.  
  54.             HotKeySet(Execute("$Button" & $i & "_Capture"), "Button" & $i & "_Click")
  55.  
  56.         Next
  57.  
  58.     ; if window is not active remove hot keys
  59.     Else
  60.  
  61.         For $i = 1 To $NumberOfButtons
  62.  
  63.             HotKeySet(Execute("$Button" & $i & "_Capture"))
  64.  
  65.         Next
  66.  
  67.     EndIf
  68.  
  69.     Sleep(100)
  70.  
  71. WEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement