AutoHotkey Community

It is currently May 27th, 2012, 10:42 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: January 23rd, 2008, 9:48 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
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


Last edited by silkcom on July 16th, 2008, 6:21 pm, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2008, 5:03 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
Can someone find a way to rewrite this script so that it works with Google Talk? I can't find any COM information on it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2008, 10:42 pm 
Offline

Joined: January 25th, 2008, 8:37 pm
Posts: 50
Location: Sweden
I don't understand, how do you use it?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2008, 11:06 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
I was using it with direct access (a launcher program that is slightly more friendly but way less powerful), and I'd just launch it.

Now i've put the code into a script. It still works very much the same, basically it just adds custom hotkeys to instant message certain people.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 12:32 am 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
Here's my new code (completely written for Autohotkey)

How to use:
-hold ctrl-alt and see a list of all your MSN contacts
-while holding ctrl-alt hit the letter for the person u want to chat to
-chat window will open and give focus (or just give focus if already openned

very useful for anyone who chats with the same people all the time (who doesn't)

Improvements needed (if u can fix it, just reply with the code):
-make the CTRL-ALT combo be easily changable
-allow for more than 26 contacts
-create hotkeys "dynamically" rather than having the huge list that we have here
-save letter for person so that it never changes (make this letter changable/configurable)
-show live status (that changes every time you hit ctrl-alt)
-be able to also show google talk list :)
-possibly bold online contacts (not sure that's possible with tooltips)
-click system tray icon (or right click) and see a list of online buddies, click on person to open chat window
Code:
;code by Silkcom with lots and lots of help from the Autohotkey forums
;max interval increased on purpose :), otherwise u get msgboxs

#MaxHotKeysPerInterval 1000
#Include COM.ahk

COM_Init()

name := 1

msn := COM_CreateObject("Messenger.UIAutomation.1")

   MyContacts := COM_Invoke(msn, "MyContacts")
        totalCount := COM_Invoke(MyContacts, "Count")
         
   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")       
            Name%A_Index% = %ThisName%
         msg = %msg%(%loopChar%) %ThisFriendlyName%`n
            loopChar := chr(asc(loopChar) + 1)
   }

   COM_Release(MyContacts)
   COM_Release(msn)


^Alt::
!Ctrl::
ToolTip %msg%
SetTimer Check, 20
Return


^!a::
Stop()
InstantMessage(Name1)
Return

^!b::
Stop()
InstantMessage(Name2)
Return

^!c::
Stop()
InstantMessage(Name3)
Return

^!d::
Stop()
InstantMessage(Name4)
Return

^!e::
Stop()
InstantMessage(Name5)
Return

^!f::
Stop()
InstantMessage(Name6)
Return

^!g::
Stop()
InstantMessage(Name7)
Return

^!h::
Stop()
InstantMessage(Name8)
Return

^!i::
Stop()
InstantMessage(Name9)
Return

^!j::
Stop()
InstantMessage(Name10)
Return

^!k::
Stop()
InstantMessage(Name11)
Return

^!l::
Stop()
InstantMessage(Name12)
Return

^!m::
Stop()
InstantMessage(Name13)
Return

^!n::
Stop()
InstantMessage(Name14)
Return
^!o::
Stop()
InstantMessage(Name15)
Return
^!p::
Stop()
InstantMessage(Name16)
Return
^!q::
Stop()
InstantMessage(Name17)
Return
^!r::
Stop()
InstantMessage(Name18)
Return
^!s::
Stop()
InstantMessage(Name19)
Return
^!t::
Stop()
InstantMessage(Name20)
Return
^!u::
Stop()
InstantMessage(Name21)
Return
^!v::
Stop()
InstantMessage(Name22)
Return
^!w::
Stop()
InstantMessage(Name23)
Return
^!x::
Stop()
InstantMessage(Name24)
Return
^!y::
Stop()
InstantMessage(Name25)
Return
^!z::
Stop()
InstantMessage(Name26)
Return


Check:
If NOT (GetKeyState("Ctrl") AND GetKeyState("Alt"))
   Stop()
Return

Stop()
{
   ToolTip
   SetTimer Check, Off
}

InstantMessage(myName)
{
    thisName := myName
    msn := COM_CreateObject("Messenger.UIAutomation.1")
    COM_Invoke(msn, "InstantMessage", thisName)
    COM_Release(msn)
}



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2008, 4:32 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
ok, here's the latest and so far greatest, still doesn't do a lot that i'd like it too, but hey it's way better than it was before.

Code:
#MaxHotKeysPerInterval 1000
#Include COM.ahk

prefix := "^!"

COM_Init()

name := 1

msn := COM_CreateObject("Messenger.UIAutomation.1")

   MyContacts := COM_Invoke(msn, "MyContacts")
        totalCount := COM_Invoke(MyContacts, "Count")
         
   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")       
            Name%A_Index% = %ThisName%
         msg = %msg%(%loopChar%) %ThisFriendlyName%`n
            hotkey % prefix . loopChar, ChatPressed
            loopChar := chr(asc(loopChar) + 1)
   }

   COM_Release(MyContacts)
   COM_Release(msn)

Return

ChatPressed:
  Index := asc(SubStr(A_ThisHotKey,1+StrLen(prefix))) - 96
  Stop()
  InstantMessage(Name%index%)
  Return
;  MsgBox Youpressed %A_ThisHotKey% (%index%)
Return


^Alt::
!Ctrl::
ToolTip %msg%
SetTimer Check, 20
Return

Check:
If NOT (GetKeyState("Ctrl") AND GetKeyState("Alt"))
   Stop()
Return

Stop()
{
   ToolTip
   SetTimer Check, Off
}

InstantMessage(myName)
{
    thisName := myName
    msn := COM_CreateObject("Messenger.UIAutomation.1")
    COM_Invoke(msn, "InstantMessage", thisName)
    COM_Release(msn)
}



way shorter than before :).


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Messenger API reference?
PostPosted: February 6th, 2008, 3:18 pm 
This script is great but I get an error at startup because I have too many contacts and loopChar is eventually incremented to an invalid value.

I thought I could work around this by modifying the script to only include contacts from one group in my contacts list but I can find no reference material for the Messenger API.

Do you have a resource for this information or any advice about how to make the modifications I mentioned above?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 6th, 2008, 4:01 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
Ya, I knew this was a possibility :) sorry.

http://msdn2.microsoft.com/en-us/library/ms631614%28VS.85%29.aspx

That's the COM interface for IMessenger. The other way that you could do it is to have it stop at Z.

I'm hoping in the future I'll get some help in making everyone an INI file. So that your list gets populated into an ini file (if it doesn't exist), and you can assign letters to people. That would be nice :).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 19th, 2008, 7:25 am 
Offline

Joined: July 15th, 2007, 1:43 am
Posts: 1320
Is it possible to check for the creation of such object?

_________________
Religion is false. >_>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 5:54 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
I'm not sure what you're asking, check for the creation of what object?

So i've decided that I'm going to start working on the INI file for this. I need some help though, here's the end goal:

someone opens the script and it gets a list of current contacts, it looks to see if the ini exists

IF ini exists
- go through the list and make sure there aren't any unknown contacts,
- assign them to available letters
- setup all the hotkeys for everyone in the ini file (which should be everyone now)

IF ini doesn't exist
- create an ini file
- create a list of everyone in the ini, start from the beginning and add them all to the list
- setup all the hotkeys for everyone in the ini file

This would allow people to setup certain letters for certain people, and remove letters from people they don't want to do.

Any help on this would be greatly appreciated


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2008, 6:02 pm 
Offline

Joined: May 15th, 2007, 8:59 pm
Posts: 169
This is an amazing Script. I would love to see this script modified into more of an nDroid 320MPH style searching.

So you press a hotkey like CTRL + ALT + M and it pops up a box where you can type in and contacts are displayed and filtered as you type. Sort of how messenger currently does when you start typing in the messenger window.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 5:57 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
I'll reply so people can see the changes.

I made this into an ini based program. It works very very nice (in my opinion).

See the code at the top, and let me know of any improvements you are able to make.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 6:21 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
Ok, one more change. I'll start including the code here too.

Version 2.002

I made it so that it only listens to keys 1-9, a-z, A-Z, otherwise it lets the user know that the line has been ignored.

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


as always, please make improvements and submit them :). Fixes are always welcome.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group