Advertisement
tabnation

intro 13

Feb 25th, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. script 1 =
  2. f1::
  3. gui, destroy
  4. Gui, Add, Text,, Click anywhere in this window.
  5. Gui, Add, Edit, w200 vMyEdit
  6. Gui, Show
  7. OnMessage(0x201, "WM_LBUTTONDOWN")
  8. return
  9.  
  10. WM_LBUTTONDOWN(wParam, lParam)
  11. {
  12. X := lParam & 0xFFFF
  13. Y := lParam 2greaterthensignshere 16
  14. if A_GuiControl
  15. Ctrl := "`n(in control " . A_GuiControl . ")"
  16. ToolTip You left-clicked in Gui window #%A_Gui% at client coordinates %X%x%Y%.%Ctrl%
  17. }
  18. return
  19.  
  20. f2::
  21. Sleep 1000 ; Give user a chance to release keys.
  22. ; Turn Monitor Off:
  23. SendMessage, 0x112, 0xF170, 2,, Program Manager
  24. ; Note for the above: Use -1 in place of 2 to turn the monitor on.
  25. ; Use 1 in place of 2 to activate the monitor's low-power mode.
  26. return
  27.  
  28. f3:: ;start screen saver WM_SYSCOMMAND
  29. SendMessage, 0x112, 0xF140, 0,, Program Manager
  30. Return
  31.  
  32. f4:: ;change lang.
  33. PostMessage, 0x50, 0, 0x4090409,, A ; 0x50 is WM_INPUTLANGCHANGEREQUEST.
  34. Return
  35.  
  36. Receiver=
  37. #SingleInstance​
  38. OnMessage(0x4a, "Receive_WM_COPYDATA") ; 0x4a is WM_COPYDATA
  39. return
  40.  
  41. Receive_WM_COPYDATA(wParam, lParam)
  42. {
  43. StringAddress := NumGet(lParam + 2*A_PtrSize) ; Retrieves the CopyDataStruct's lpData member.
  44. CopyOfData := StrGet(StringAddress) ; Copy the string out of the structure.
  45. ; Show it with ToolTip vs. MsgBox so we can return in a timely fashion:
  46. ToolTip %A_ScriptName%`nReceived the following string:`n%CopyOfData%
  47. sleep 5000
  48. tooltip
  49. return true ; Returning 1 (true) is the traditional way to acknowledge this message.
  50. }
  51.  
  52.  
  53. Sender =
  54. TargetScriptTitle := "Receiver.ahk ahk_class AutoHotkey"
  55.  
  56. f1:: ; f1 Press it to show an InputBox for entry of a message string.
  57. InputBox, StringToSend, Send text via WM_COPYDATA, Enter some text to Send:
  58. if ErrorLevel ; User pressed the Cancel button.
  59. return
  60. result := Send_WM_COPYDATA(StringToSend, TargetScriptTitle)
  61. if (result = "FAIL")
  62. MsgBox SendMessage failed. Does the following WinTitle exist?:`n%TargetScriptTitle%
  63. else if (result = 0)
  64. MsgBox Message sent but the target window responded with 0, which may mean it ignored it.
  65. return
  66.  
  67. Send_WM_COPYDATA(ByRef StringToSend, ByRef TargetScriptTitle) ; ByRef saves a little memory in this case.
  68. ; This function sends the specified string to the specified window and returns the reply.
  69. ; The reply is 1 if the target window processed the message, or 0 if it ignored it.
  70. {
  71. VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0) ; Set up the structure's memory area.
  72. ; First set the structure's cbData member to the size of the string, including its zero terminator:
  73. SizeInBytes := (StrLen(StringToSend) + 1) * (A_IsUnicode ? 2 : 1)
  74. NumPut(SizeInBytes, CopyDataStruct, A_PtrSize) ; OS requires that this be done.
  75. NumPut(&StringToSend, CopyDataStruct, 2*A_PtrSize) ; Set lpData to point to the string itself.
  76. Prev_DetectHiddenWindows := A_DetectHiddenWindows
  77. Prev_TitleMatchMode := A_TitleMatchMode
  78. DetectHiddenWindows On
  79. SetTitleMatchMode 2
  80. TimeOutTime := 4000 ; Optional. Milliseconds to wait for response from receiver.ahk. Default is 5000
  81. ; Must use SendMessage not PostMessage.
  82. SendMessage, 0x4a, 0, &CopyDataStruct,, %TargetScriptTitle%,,,, %TimeOutTime% ; 0x4a is WM_COPYDATA.
  83. DetectHiddenWindows %Prev_DetectHiddenWindows% ; Restore original setting for the caller.
  84. SetTitleMatchMode %Prev_TitleMatchMode% ; Same.
  85. return ErrorLevel ; Return SendMessage's reply back to our caller.
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement