; Count characters as you type ; Date: 05/08/2007 ;Last Updated: 09/08/2007 ; Refer: hxxp://www.donationcoder.com/Forums/bb/index.php?topic=9420 #SingleInstance force #InstallKeybdHook #Persistent appname=Count-as-you-type ; to get a better name vernum=1.36 INI_File=count.ini Gosub, Get_INI Gosub, MENU Gosub, Timer Return Get_INI: IfNotExist, %INI_File% { comments= comments=`;%A_Space%Ini settings for "Count-as-you-type" script. comments=%comments%`n`;%A_Space% comments=%comments%`n`;%A_Space%This file contains some of the configurable settings. comments=%comments%`n`;%A_Space%for maximum character, please do not enter unreasonable numbers. :) comments=%comments%`n`;%A_Space%while eMail Apps go by code.. comments=%comments%`n`;%A_Tab%Mozilla Thunderbird=0 comments=%comments%`n`;%A_Tab%Microsoft Outlook=1 comments=%comments%`n`;%A_Tab%Outlook Express=2 comments=%comments%`n`;%A_Space%-------------------------------------- comments=%comments%`n`;%A_Space%You may edit this file but not while the script is running. comments=%comments%`n`; FileAppend,%comments%,%INI_File% maxchar=160 ;read from ini emailclient=2 ;default setting, as OE is available on every Win-machine quicksend=0 ;IniWrite, Value, Filename, Section, Key IniWrite,%maxchar%,%INI_File%,Settings,MaxChar IniWrite,%emailclient%,%INI_File%,Settings,EmailApp IniWrite,%quicksend%,%INI_File%,Settings,QuickSend IniWrite,%emailaddress%,%INI_File%,Settings,Recipient } Else ;INI file exists, read from it { ;IniRead, OutputVar, Filename, Section, Key [, Default] IniRead,maxchar,%INI_File%,Settings,MaxChar,160 IniRead,emailclient,%INI_File%,Settings,EmailApp,2 IniRead,quicksend,%INI_File%,Settings,QuickSend,0 IniRead,emailaddress,%INI_File%,Settings,Recipient, If emailclient=0 { emailwindow=Compose`: (no subject) default_app=Mozilla Thunderbird } Else If emailclient=1 { emailwindow=Untitled Message default_app=Microsoft Outlook } Else If emailclient=2 { emailwindow=New Message default_app=Outlook Express } ;uncomment later TrayTip,%appname%, Max. Chars=%maxchar%`nEmail App=%default_app%,,2 } Return MENU: Menu, tray, NoStandard Menu, tray, DeleteAll Menu, tray, Tip, %appname% v%vernum% Menu, tray, Icon, %A_WinDir%\System32\shell32.dll, 155 Menu, Tray, Add, ShowGUI, LaunchGUI Menu, tray, Add, Options, Settings Menu, tray, Add, Menu, tray, Add, Quit, QUIT Menu, Tray, Default, ShowGUI Return Timer: SetTimer, OEWindow, 500 Return OEWindow: IfWinActive %emailwindow% { If NotSoSoon ;closed while OE compose window is active. { WinWaitClose %emailwindow% NotSoSoon=0 ;reset flag, closed while OE compose window is active. Return } SetTimer, OEWindow, Off WinGetPos, X, Y, Width, Height, %emailwindow% ;WinGet, active_id, ID, A ;for future use MyX:=X+Width ;TrayTip,%appname%, %X% %Width% %MyX% %MyY%,,2 Gosub, APPGUI SetTimer, WatchCharCount, 500 ;When compose window is closed, close GUI with it WinWaitClose %emailwindow% NotSoSoon=0 ;reset flag, closed while OE compose window is active. GoSub, ClosetoTray ;Gui to close since compose window is closed. } Return LaunchGUI: Gosub, APPGUI SetTimer, WatchCharCount, 500 Return APPGUI: Gui, Destroy Gui, +alwaysontop Gui, Font, s10, Verdana ;Totally Nod5's code - thanks, dude! ;----NEW2 If quicksend=1 Gui, Add, Checkbox, x218 y148 w100 h20 Checked vToggleCheckBox gToggleCheckBox, Quick-Send else Gui, Add, Checkbox, x218 y148 w100 h20 vToggleCheckBox gToggleCheckBox, Quick-Send Gui, Add, Button, gCopySend x6 y190 w90 h25, &Send Gui, Add, Button, gCopyOnly x6 y190 w90 h25, &Copy GoSub, ToggleCheckBox ;----NEW2 If MeClose Gui, Add, Edit, x6 y10 w320 h130, %MeClose% Else Gui, Add, Edit, x6 y10 w320 h130, Gui, Font, w200, Tahoma Gui, Add, Text, x6 y150 w150 h20, Character count: Gui, Add, Edit, x108 y150 w50 h20, ;MeChar -> variable for MaxChar's contents Gui, Add, Text, x162 y150 w55 h20, / %maxchar% ;Gui, Add, Text, x182 y150 w50 h20, Gui, Add, Button, x116 y190 w90 h25, C&lear Gui, Add, Button, gClosetoTray x226 y190 w90 h25, Close to Tray IfWinNotExist %emailwindow% Gui, Show, Center, %appname% v%vernum% Else Gui, Show, x%MyX% y%Y% h225 w351, %appname% v%vernum% NotSoSoon=0 ;reset flag, closed while OE compose window is active. WinGet, active_id, ID, A ;TrayTip, %appname%, The active window's ID is "%active_id%". Return WatchCharCount: GuiControlGet, MeChar, , Edit1, Text ;Retrieve content of the edit control StringLen, length, MeChar ControlSetText, Edit2, %length%, ahk_class AutoHotkeyGUI If length > %maxchar% { TrayTip,%appname%, You have exceeded the maximum number of characters!,,2 ;Gui, Flash ;SoundPlay, %A_WinDir%\Media\chord.wav ;too noisy } Else TrayTip ;remove tray-tip ;Gui, Flash, Off Return ToggleCheckBox: Gui, Submit, NoHide ;Switch buttons when toggling the check-box ;Totally Nod5's code - thanks, dude! ;-----NEW2 --- don't destroy+create win, just change the controls IniWrite,%ToggleCheckBox%,%INI_File%,Settings,QuickSend quicksend=%ToggleCheckBox% if ToggleCheckBox { GuiControl, Show, &Send GuiControl, Enable, &Send GuiControl, Hide, &Copy GuiControl, Disable, &Copy } else { GuiControl, Hide, &Send GuiControl, Disable, &Send GuiControl, Show, &Copy GuiControl, Enable, &Copy } Return CopySend: GoSub, CopyOnly ;mailto with clipboard content ;phonenumber = emailaddress ;subject not needed for SMS emails If allgood=1 { Run, mailto:%emailaddress%?subject=&body=%MeChar% allgood=0 ;small boolean flag } Return CopyOnly: GuiControlGet, MeChar, , Edit1, Text ;Retrieve content of the edit control If StrLen(MeChar) > 0 { clipboard = ; Clear the clipboard clipboard = %MeChar% ; Set the clipboard with new content TrayTip,%appname%,The new clipboard contents:`n%clipboard%.,,1 allgood=1 ;small boolean flag } Else TrayTip,%appname%,There is nothing to copy.,,1 Return ButtonClear: GuiControl, , Edit1, Return GuiEscape: ClosetoTray: ;GuiClose resets timer & hides the gui GuiControlGet, MeClose, , Edit1, Text ;Retrieve content of the edit control SetTimer, WatchCharCount, Off Gosub, Timer Gui, Hide IfWinExist %emailwindow% NotSoSoon=1 ;closed while OE compose window is active. so needs double-click from tray Return GuiClose: QUIT: ExitApp ;Configuration Window Settings: ;Gui, 2:+Owner1 IfWinExist ahk_id %active_id% WinSet,AlwaysOnTop,Off,ahk_id %active_id% Gui, 2:Destroy Gui, 2:Font, s10, Verdana Gui, 2:Add, GroupBox, x10 y5 w250 h120, Preferred E-mail App Gui, 2:Add, Radio, vRadioB1 x20 y30 w150 h20, Mozilla Thunderbird Gui, 2:Add, Radio, vRadioB2 x20 y60 w150 h20, Microsoft Outlook Gui, 2:Add, Radio, vRadioB3 x20 y90 w150 h20, Outlook Express If emailclient=0 GuiControl, 2:, RadioB1, 1 Else If emailclient=1 GuiControl, 2:, RadioB2, 1 Else If emailclient=2 GuiControl, 2:, RadioB3, 1 Gui, 2:Add, GroupBox, x10 y130 w250 h60, Maximum Characters allowed Gui, 2:Add, Text, x20 y155 w110 h20, Enter a number here: Gui, 2:Add, Edit, vNewMaxChar x135 y155 w60 h20 Number Limit4, %maxchar% Gui, 2:Add, Button, x30 y200 w90 h25 gOptionOk Default,&OK Gui, 2:Add, Button, x141 y200 w90 h25 gOptionCancel,&Cancel Gui, 2:Show, Center w275 h245, Configuration Return 2GuiClose: IfWinExist ahk_id %active_id% WinSet,AlwaysOnTop,On,ahk_id %active_id% Gui, 2:Destroy Return OptionOk: Gui, 2:Submit If RadioB1=1 emailclient=0 Else If RadioB2=1 emailclient=1 Else If RadioB3=1 emailclient=2 maxchar=%NewMaxChar% ;Write settings to INI file IniWrite,%maxchar%,%INI_File%,Settings,MaxChar IniWrite,%emailclient%,%INI_File%,Settings,EmailApp Return OptionCancel: GoSub, 2GuiClose Return