UPDATE:
I've changed the code to listen to an INI type file. It creates it if it doesn't exist, and makes it very easy to pick which character goes with which friend.
2.001 - Added the ini stuff
2.002 - Did a little "error handling"
Version 2.002
Code:
#SingleInstance force
#MaxHotKeysPerInterval 1000
#Include COM.ahk
;Main:
COM_Init()
Menu, Tray, NoStandard
Menu, Tray, Tip,MSN InstaChat (Ctrl-Alt for Tooltip)
Menu, Tray, Add, Check For New Emails, CheckForMore
Menu, Tray, Add
Menu, Tray, Add, Reload INI, Reload
Menu, Tray, Add, Exit, CloseProgram
Menu, Tray, Default, Reload INI
delim := "|"
tooltipKeys := "^!"
IfNotExist, InstaChat.ini
gosub CreateNewIniFile
gosub LoadIniFile
EmptyMem()
Return
ChatPressed:
index := SubStr(A_ThisHotKey,1+StrLen(tooltipKeys))
Stop()
InstantMessage(keys%index%)
EmptyMem()
Return
^Alt::
!Ctrl::
ToolTip %msg%
SetTimer Check, 20
Return
Check:
If NOT (GetKeyState("Ctrl") AND GetKeyState("Alt"))
Stop()
Return
Stop()
{
ToolTip
SetTimer Check, Off
EmptyMem()
}
InstantMessage(myName)
{
thisName := myName
msn := COM_CreateObject("Messenger.UIAutomation.1")
COM_Invoke(msn, "InstantMessage", thisName)
COM_Release(msn)
EmptyMem()
}
CheckForMore:
msn := COM_CreateObject("Messenger.UIAutomation.1")
MyContacts := COM_Invoke(msn, "MyContacts")
started := false
Loop % COM_Invoke(MyContacts, "Count")
{
AllContactList := COM_Invoke(MyContacts, "Item", A_Index-1)
ThisFriendlyName := COM_Invoke(AllContactList, "FriendlyName")
ThisName := COM_Invoke(AllContactList, "SigninName")
notfound := true
Loop % cnt
if (emails%A_Index% == ThisName)
notfound := false
if (notfound)
{
if (started)
FileAppend `n, InstaChat.ini
started := true
lineToAdd = 0%delim%%delim%%ThisName%%delim%%ThisFriendlyName%
FileAppend %lineToAdd%, InstaChat.ini
}
}
COM_Release(MyContacts)
COM_Release(msn)
EmptyMem()
Return
CreateNewIniFile:
msn := COM_CreateObject("Messenger.UIAutomation.1")
MyContacts := COM_Invoke(msn, "MyContacts")
loopChar := "a"
Loop % COM_Invoke(MyContacts, "Count")
{
AllContactList := COM_Invoke(MyContacts, "Item", A_Index-1)
ThisFriendlyName := COM_Invoke(AllContactList, "FriendlyName")
ThisName := COM_Invoke(AllContactList, "SigninName")
lineToAdd = 1%delim%%loopChar%%delim%%ThisName%%delim%%ThisFriendlyName%
if (A_Index > 1)
FileAppend `n, InstaChat.ini
FileAppend %lineToAdd%, InstaChat.ini
loopChar := chr(asc(loopChar) + 1)
}
COM_Release(MyContacts)
COM_Release(msn)
EmptyMem()
Return
LoadIniFile:
cnt := 1
Loop, read, InstaChat.ini
{
LineNumber = %A_Index%
thisLine := A_LoopReadLine
if (thisLine != "")
{
thisChar =
ignoreLine =
record := true
Loop, parse, thisLine, %delim%
{
if (A_Index == 1)
{
if (A_LoopField != "1")
{
record := false
}
}
else if (A_Index == 2)
{
if (record)
{
If ( Asc(A_LoopField) >= 65 && Asc(A_LoopField) <= 90 ) || ( Asc(A_LoopField) >= 97 && Asc(A_LoopField) <= 122) || ( Asc(A_LoopField) >= 48 && Asc(A_LoopField) <= 57 )
thisChar := A_LoopField
else
{
msgbox Sorry, you must only use values 1-9, a-z, or A-Z.`nYou used (%A_LoopField%) and that line has been ignored
record := false
}
}
}
else if (A_Index == 3)
{
emails%cnt% := A_LoopField
cnt := cnt + 1
if (record)
if (thisChar != "")
{
keys%thisChar% := A_LoopField
hotkey % tooltipKeys . thisChar, ChatPressed
}
}
else if (A_Index == 4)
{
if (record)
msg = %msg%(%thisChar%) %A_LoopField%`n
}
}
}
}
EmptyMem()
Return
/*
File -> exit, or tray exit. Pretty obvious
*/
CloseProgram:
ExitApp
Return
/*
Borrowed from online. Basically allows you to clear out the cache/memory
of any process.
Improvements:
None to this function, but I'd like to make a keyword that allows you to
empty the mem of the currently active window. Or to a dropdown box. Would
be extra nice to clear out mem on yahoo widgets :)
*/
EmptyMem(PID="This Script")
{
pid:=(pid="This Script") ? DllCall("GetCurrentProcessId") : pid
h:=DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", pid)
DllCall("SetProcessWorkingSetSize", "UInt", h, "Int", -1, "Int", -1)
DllCall("CloseHandle", "Int", h)
}
/*
Because I have to call reload from a menu
*/
Reload:
Reload
Return
Please make suggestions
ORIGINAL:
This is a simple script, that takes in a parameter (for my uses) of a contacts name in ur MSN contacts, and opens a chat window.
Could easily be changed to do so for other reasons.
Updated Code (Thanks to Lexikos for code):
Code:
#NoTrayIcon
#Include COM.ahk
StringReplace, 1, 1, ",, All
COM_Init()
name := 1
msn := COM_CreateObject("Messenger.UIAutomation.1")
if 0 < 1
{
MyContacts := COM_Invoke(msn, "MyContacts")
Loop % COM_Invoke(MyContacts, "Count")
{
; Puts contacts in AllContactList1, AllContactList2, etc.
AllContactList := COM_Invoke(MyContacts, "Item", A_Index-1)
ThisName := COM_Invoke(AllContactList, "SigninName")
msg = %msg%`n%ThisName%
}
msgbox %msg%
}
else
{
COM_Invoke(msn, "InstantMessage", %name%)
}
COM_Release(MyContacts)
COM_Release(msn)
ExitApp
COM Library