OSC extension for Autohotkey, a DLL
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.6 KiB

  1. #NoEnv
  2. ; #Warn
  3. SendMode Input
  4. SetWorkingDir %A_ScriptDir% ; Until here, this is the default script template
  5. ; Get handle to this running script instance
  6. Gui +LastFound
  7. hWnd := WinExist()
  8. ; just for convenience, you also could use the "magic numbers" directly
  9. global oscTypeNone := 1
  10. global oscTypeInt := 2
  11. global oscTypeFloat := 4
  12. global oscTypeString := 8
  13. global oscTypeAll := 0xffffffff
  14. ; Load DLL and open network port for OSC (7001)
  15. DllCall("LoadLibrary", "Str", "OSC2AHK.dll", "Ptr")
  16. DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7001)
  17. ; Tell the DLL to post a system message with ID 0x1001 when a OSC message with address "/test1" and type string is received.
  18. DllCall("OSC2AHK.dll\addListener", AStr, "/test1", UInt, 0x1001, UInt, oscTypeString)
  19. ; Tell AHK to invoke the function msghandlerTest1 when a windows message with ID 0x1001 is received
  20. OnMessage(0x1001, "msghandlerTest1")
  21. ; This function effectively is called for each OSC message as specified above
  22. msghandlerTest1(oscType, data, msgID, hwnd)
  23. {
  24. ; Check that we really received a string message (kind of redundant for this example)
  25. if (oscType = oscTypeString)
  26. {
  27. ; String cannot be passed via system messages,
  28. ; so the string is buffered in the DLL and we only get a unique identifier in the "data" variable.
  29. ; To get the actual string, we use the getStringData() DLL-call
  30. VarSetCapacity(theString, 20) ; prepare variable to store string in with sufficient size
  31. theString := DllCall("OSC2AHK.dll\getStringData", str, theString, UInt, 20, UInt, data, AStr)
  32. msgbox,Got string: %theString%
  33. }
  34. }
  35. ; Shutdown the script with Shift+ESC
  36. +Esc::
  37. ExitApp