Advertisement
Ex0rpl4net

Untitled

Jun 27th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. #SingleInstance force
  2. run,download.ahk
  3.  
  4. SendData("download", "Var," "random text") ;Var is before the comma, which means that the variable that will be assigned is %Var%. The text assigned to it is what comes after the comma, i.e. %A_ThisHotkey%
  5.  
  6. return
  7. SendData(wParam, lParam) ; http://www.autohotkey.com/board/topic/77796-senddata-sending-data-between-scripts-with-sendmessage/ - May 3, 2013
  8. { ; wParam = which script; lParam = data in CSV format
  9. Global
  10. Static Label
  11. Local UseError := False
  12. Local a, b, c, Ptr := A_PtrSize = "" ? "UInt" : "Ptr", Psz := A_PtrSize = "" ? 4 : A_PtrSize
  13. If (wParam = True) {
  14. OnMessage(0x4a, A_ThisFunc)
  15. If lParam and !IsLabel(Label := lParam)
  16. MsgBox, 262160, %A_ScriptName% - %A_ThisFunc%(): Error, Label "%Label%" does not exist.
  17. } Else If (wParam = False) {
  18. c := A_IsUnicode ? "W" : "A", a := NumGet(lParam + 0, 2 * Psz, Ptr), VarSetCapacity(b, DllCall("lstrlen" c, Ptr, a) << (c = "W")), DllCall("lstrcpy" c, "Str", b, Ptr, a)
  19. Loop, Parse, b, CSV
  20. If (A_Index = 1) and !Label
  21. a := A_LoopField
  22. Else If (1 & A_Index) ^ !Label
  23. b := A_LoopField
  24. Else
  25. %b% := A_LoopField
  26. If Label or IsLabel(a)
  27. SetTimer, % Label ? Label : a, -1
  28. Else
  29. MsgBox, 262160, %A_ScriptName% - %A_ThisFunc%(): Error, Label "%a%" does not exist.
  30. Return True
  31. } Else {
  32. a := A_DetectHiddenWindows, b := A_TitleMatchMode
  33. DetectHiddenWindows, On
  34. SetTitleMatchMode, Regex
  35. VarSetCapacity(c, 3 * Psz, 0), NumPut((StrLen(lParam) + 1) * (A_IsUnicode ? 2 : 1), c, Psz), NumPut(&lParam, c, 2 * Psz)
  36. SendMessage, 0x4a, 0, &c, , i)\\\Q%wParam%\E(\.(ahk|exe))? ahk_class AutoHotkey ; edit this regular expression to your liking
  37. If (ErrorLevel <> True) and UseError
  38. MsgBox, 262160, %A_ScriptName% - %A_ThisFunc%(): Error, % "ErrorLevel:`t" ErrorLevel "`n" ErrorLevel ? "Script """ wParam """ did not receive the message; the script may not exist." : "Message sent but the target window responded with 0, which may mean it ignored it."
  39. DetectHiddenWindows, %a%
  40. SetTitleMatchMode, %b%
  41. }
  42. }
  43.  
  44.  
  45. ;script 2
  46.  
  47. SendData(True, "ReceiveData") ;Autorun. "ReceiveData" means go to this label any time data is received
  48. Return
  49.  
  50. ReceiveData:
  51. MsgBox, The variable `%var`% has been set to %var%.
  52. Return
  53.  
  54.  
  55. SendData(wParam, lParam) ; http://www.autohotkey.com/board/topic/77796-senddata-sending-data-between-scripts-with-sendmessage/ - May 3, 2013
  56. { ; wParam = which script; lParam = data in CSV format
  57. Global
  58. Static Label
  59. Local UseError := False
  60. Local a, b, c, Ptr := A_PtrSize = "" ? "UInt" : "Ptr", Psz := A_PtrSize = "" ? 4 : A_PtrSize
  61. If (wParam = True) {
  62. OnMessage(0x4a, A_ThisFunc)
  63. If lParam and !IsLabel(Label := lParam)
  64. MsgBox, 262160, %A_ScriptName% - %A_ThisFunc%(): Error, Label "%Label%" does not exist.
  65. } Else If (wParam = False) {
  66. c := A_IsUnicode ? "W" : "A", a := NumGet(lParam + 0, 2 * Psz, Ptr), VarSetCapacity(b, DllCall("lstrlen" c, Ptr, a) << (c = "W")), DllCall("lstrcpy" c, "Str", b, Ptr, a)
  67. Loop, Parse, b, CSV
  68. If (A_Index = 1) and !Label
  69. a := A_LoopField
  70. Else If (1 & A_Index) ^ !Label
  71. b := A_LoopField
  72. Else
  73. %b% := A_LoopField
  74. If Label or IsLabel(a)
  75. SetTimer, % Label ? Label : a, -1
  76. Else
  77. MsgBox, 262160, %A_ScriptName% - %A_ThisFunc%(): Error, Label "%a%" does not exist.
  78. Return True
  79. } Else {
  80. a := A_DetectHiddenWindows, b := A_TitleMatchMode
  81. DetectHiddenWindows, On
  82. SetTitleMatchMode, Regex
  83. VarSetCapacity(c, 3 * Psz, 0), NumPut((StrLen(lParam) + 1) * (A_IsUnicode ? 2 : 1), c, Psz), NumPut(&lParam, c, 2 * Psz)
  84. SendMessage, 0x4a, 0, &c, , i)\\\Q%wParam%\E(\.(ahk|exe))? ahk_class AutoHotkey ; edit this regular expression to your liking
  85. If (ErrorLevel <> True) and UseError
  86. MsgBox, 262160, %A_ScriptName% - %A_ThisFunc%(): Error, % "ErrorLevel:`t" ErrorLevel "`n" ErrorLevel ? "Script """ wParam """ did not receive the message; the script may not exist." : "Message sent but the target window responded with 0, which may mean it ignored it."
  87. DetectHiddenWindows, %a%
  88. SetTitleMatchMode, %b%
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement