Try this.
I've changed my code from "
http://www.autohotkey.com/forum/topic36712.html&highlight=skype+api" to be GUI-less, or better, to leave the GUI invisible:
Code:
;---------------------------------------------------------------------------
; Define constants
;---------------------------------------------------------------------------
SKYPECONTROLAPI_ATTACH_SUCCESS = 0
SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION = 1
SKYPECONTROLAPI_ATTACH_REFUSED = 2
SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE = 3
SKYPECONTROLAPI_ATTACH_API_AVAILABLE = 0x8001
WM_COPYDATA = 0x4a
;---------------------------------------------------------------------------
; Register Skype messages
;---------------------------------------------------------------------------
SkypeControlAPIDiscover := DllCall( "RegisterWindowMessage", Str,"SkypeControlAPIDiscover" )
SkypeControlAPIAttach := DllCall( "RegisterWindowMessage", Str,"SkypeControlAPIAttach" )
;---------------------------------------------------------------------------
; Invisible GUI
;---------------------------------------------------------------------------
Gui, Show, x0 y0 h0 w0
;---------------------------------------------------------------------------
; Obtain id of (this) client window
;---------------------------------------------------------------------------
hGui := WinExist("A")
OnMessage(SkypeControlAPIAttach, "SkypeAttach")
OnMessage(WM_COPYDATA, "SkypeReceive")
SendMessage, SkypeControlAPIDiscover, hGui,,, ahk_id 0xFFFF
Return
;---------------------------------------------------------------------------
; Writes text to the Skype API by sending WM_COPYDATA message
;---------------------------------------------------------------------------
writeApi(textToWrite) {
global
;---------------------------------------------------------------------------
; Escape if Skype API is not available
;---------------------------------------------------------------------------
If !hSKYPE_API
Return
;---------------------------------------------------------------------------
; Fill the CopyDataStruct structure to be sent by WM_COPYDATA
;---------------------------------------------------------------------------
DetectHiddenWindows On
SetTitleMatchMode 2
VarSetCapacity(CopyDataStruct, 12, 0) ; Set up the structure's memory area.
NumPut(StrLen(textToWrite) + 1, CopyDataStruct, 4) ; OS requires that this be done.
NumPut(&textToWrite, CopyDataStruct, 8) ; Set lpData to point to the string itself.
;---------------------------------------------------------------------------
; Issue WM_COPYDATA message to Skype API
;---------------------------------------------------------------------------
SendMessage, WM_COPYDATA, hGui, &CopyDataStruct,, ahk_id %hSKYPE_API%
}
;---------------------------------------------------------------------------
; This function is invoked upon incoming SkypeControlAPIAttach message
;---------------------------------------------------------------------------
SkypeAttach(wParam, lParam, msg, hwnd) {
global
;---------------------------------------------------------------------------
; The Skype API handle is returned with WPARAM, if successfully attached
;---------------------------------------------------------------------------
If (lParam = SKYPECONTROLAPI_ATTACH_SUCCESS)
hSKYPE_API := wParam
}
;---------------------------------------------------------------------------
; This function is invoked upon incoming WM_COPYDATA message
; It is the sample on the bottom of the OnMessage() help page
;---------------------------------------------------------------------------
SkypeReceive(wParam, lParam) {
;---------------------------------------------------------------------------
; This is the address of CopyDataStruct's lpData member
;---------------------------------------------------------------------------
lpDataAddress := lParam + 8 ; .
lpData := 0
;---------------------------------------------------------------------------
; For each byte in the lpData integer
;---------------------------------------------------------------------------
Loop 4 ; For each byte in the lpData integer
{
;---------------------------------------------------------------------------
; Build the integer from its bytes
;---------------------------------------------------------------------------
lpData := lpData | (*lpDataAddress << 8 * (A_Index - 1))
;---------------------------------------------------------------------------
; Move on to the next byte
;---------------------------------------------------------------------------
lpDataAddress += 1
}
;---------------------------------------------------------------------------
; lpData contains the address of the string to be copied
; (must be a zero-terminated string)
;---------------------------------------------------------------------------
DataLength := DllCall("lstrlen", UInt, lpData)
If DataLength <= 0
msgbox blank received
Else
{
VarSetCapacity(textReceived, DataLength)
DllCall("lstrcpy", "str", textReceived, "uint", lpData) ; Copy the string out of the structure.
msgbox % textReceived
}
Return true
}
Use the
writeApi("set userstatus DND") function to send out your command, and find received messages in "SkypeReceive".