matty
Scripting Guru
    
Posts: 8328 Reputation: 109
40 / / 
Joined: Dec 2002
Status: Away
|
RE: Timer from a form
You don't NEED to use the Messenger Plus! API.
Code to call the event in the plugin.
code: Public Function ParseCommand(ByVal sCommand As String, ByVal sCommandArg As String, ByVal oConversationWnd As Object, ByRef sResult As String) As Boolean
If (StrComp(LCase(sCommand), "/xsample", vbTextCompare) = 0) Then
sResult = ""
DoEvents
Sleep 5000
SendText "/nick " & MyNickName, True, True
If SendText = True then
Sleep 5000
SendText "/brb", True, True
End If
ParseCommand = True
Exit Function
End If
ParseCommand = False
End Function
Declarations in the Module
code: Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Const VK_RETURN = &HD
Public Const WM_CHAR = &H102
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public hDirectUI As Long
Public hPrevWnd As Long
Public i As Integer
Public imwindowclass As Long
Module Code
code: Public Sub SendText(sText As String, Optional bSend As Boolean = False, Optional bKeepFocus As Boolean = True) As Boolean
imwindowclass = FindWindow("imwindowclass", vbNullString)
If imwindowclass = 0 Then MsgBox "A conversation window needs to be open before setting text.", vbInformation + vbOKOnly, "Error:": SendText = False: Exit Sub
hDirectUI = FindWindowEx(imwindowclass, 0, "DirectUIHWND", vbNullString)
hPrevWnd = GetForegroundWindow
'This bit idles code execution until the window is in focus
'the IM window must be in focus to recieve WM_CHAR notifications
Do
Call SetForegroundWindow(hDirectUI)
Loop Until GetForegroundWindow = hDirectUI
'Post each character
For i = 1 To Len(sText)
Call PostMessage(hDirectUI, WM_CHAR, Asc(Mid(sText, i, 1)), 0)
Next i
'Simulate the enter key being pressed if necessary
If bSend Then
Call PostMessage(hDirectUI, WM_KEYDOWN, VK_RETURN, 0&)
Call PostMessage(hDirectUI, WM_KEYUP, VK_RETURN, 0&)
End If
'If the window is not wanted to be kept in focus then bring back the previous
If Not bKeepFocus Then
Call SetForegroundWindow(hPrevWnd)
End If
SendText = True
End Sub
Yes I know its a lot of code but it would do the job, unless they dont have any conversation windows open
|
|