; Count characters as you type ; Date: 05/08/2007 ;Last Updated: 17/08/2007 ; Refer: hxxp://www.donationcoder.com/Forums/bb/index.php?topic=9420 #SingleInstance force #InstallKeybdHook #Persistent DetectHiddenWindows, On SetTitleMatchMode, 2 appname=Count-as-you-type ; to get a better name vernum=1.38 INI_File=count.ini Gosub, Get_INI Gosub, MENU Gosub, Timer Return Get_DPI: ; Source: http://www.autohotkey.com/forum/viewtopic.php?t=7489 hdc := DllCall("GetDC", UInt, 0) dpi := DllCall("GetDeviceCaps", UInt, hdc, Int, 90) ; 90 is LOGPIXELSY. DllCall("ReleaseDC", UInt, 0, UInt, hdc) 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 { default_app=Mozilla Thunderbird emailwindow=Compose`: (no subject) } Else If emailclient=1 { default_app=Microsoft Outlook emailwindow=Untitled - Message ;emailwindow=Untitled Message } Else If emailclient=2 { default_app=Outlook Express emailwindow=New Message } ;uncomment later TrayTip,%appname%, Max. Chars=%maxchar%`nEmail App=%default_app%,,1 } 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 } WinGet, MaxWin, MinMax, %emailwindow% WinGet, emailwin_id, ID, %emailwindow% WinGetPos, X, Y, Width, Height, %emailwindow% MyX:=X+Width Gosub, APPGUI ;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 Return APPGUI: Gui, Destroy Gui, +alwaysontop ;Check the dpi settings and disable the s10 font setting to avoid distortion in 120 dpi Gosub, Get_DPI If dpi <> 96 Gui, Font,, Verdana Else Gui, Font, s10, Verdana Gui, Add, GroupBox, x336 y0 w125 h150, Gui, Add, GroupBox, x6 y150 w325 h55, Gui, Add, GroupBox, x336 y150 w125 h55, w00t! If MeClose Gui, Add, Edit, gCountNow vCountNow x6 y10 w320 h140, %MeClose% Else Gui, Add, Edit, gCountNow vCountNow x6 y10 w320 h140, ;Totally Nod5's code - thanks, dude! ;----NEW2 If quicksend=1 Gui, Add, Checkbox, x346 y120 w110 h20 Checked vToggleCheckBox gToggleCheckBox, Quick-Send Else Gui, Add, Checkbox, x346 y120 w110 h20 vToggleCheckBox gToggleCheckBox, Quick-Send Gui, Add, Button, gCopySend x16 y170 w90 h25, &Send Gui, Add, Button, gCopyOnly x16 y170 w90 h25, &Copy GoSub, ToggleCheckBox ;----NEW2 Gui, Font, w200, Tahoma Gui, Add, Text, x346 y20 w110 h20, Character count: Gui, Add, Edit, vXCounter x346 y40 w40 h20 Number, Gui, Add, Text, vMaxTotal x386 y40 w70 h20, / %maxchar% Gui, Add, Text, x346 y70 w110 h20,Word count: Gui, Add, Edit, vYCounter x346 y90 w40 h20 Number, Gui, Add, Button, x116 y170 w90 h25, C&lear Gui, Add, Button, gClosetoTray x216 y170 w90 h25, Close to Tray IfWinNotExist %emailwindow% Gui, Show, Center, %appname% v%vernum% Else { If MaxWin=1 Gui, Show, Center, %appname% v%vernum% Else Gui, Show, x%MyX% y%Y%, %appname% v%vernum% } NotSoSoon=0 ;reset flag, closed while OE compose window is active. GoSub, CountNow ; get original char count Return CountNow: ;--- update counter Gui, Submit, NoHide GuiControlGet, xtext,,CountNow StringLen, xlen, xtext GuiControl,,XCounter, %xlen% If StrLen(xtext) <> 0 { RegExReplace(xtext, "\S(?:\s|$)", "", Count) GuiControl,,YCounter, % Count } Else { GuiControl,,YCounter, 0 ;set word count to zero } If xlen > %maxchar% { TrayTip,%appname%, You have exceeded the maximum number of characters!,,2 SoundPlay, %A_WinDir%\Media\ding.wav } Else TrayTip ;remove tray-tip 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 If allgood=1 { IfWinExist ahk_id %emailwin_id% WinClose ;NotSoSoon=1 ;meant to be used as stand-alone so don't activate OE 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, GoSub, CountNow Return GuiEscape: ClosetoTray: ;GuiClose resets timer & hides the gui GuiControlGet, MeClose, , Edit1, Text ;Retrieve content of the edit control 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 %appname% v%vernum% WinSet,AlwaysOnTop,Off, %appname% v%vernum% Gui, 2:Destroy ;Check the dpi settings and disable the s10 font setting to avoid distortion in 120 dpi If dpi <> 96 Gui, 2:Font, , Verdana Else 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 %appname% v%vernum% WinSet,AlwaysOnTop,On, %appname% v%vernum% Gui, 2:Destroy Return OptionOk: Gui, 2:Submit ;Msgbox, 0, Debug, Radio1 is %RadioB1%`nRadio2 is %RadioB2%`nRadio3 is %RadioB3% If RadioB1=1 emailclient=0 Else If RadioB2=1 emailclient=1 Else If RadioB3=1 emailclient=2 IfNotEqual, maxchar, %NewMaxChar% { maxchar=%NewMaxChar% ;Write settings to INI file IniWrite,%maxchar%,%INI_File%,Settings,MaxChar GuiControl, 1:, MaxTotal, / %maxchar% } IniWrite,%emailclient%,%INI_File%,Settings,EmailApp Gosub, Get_INI ;re-initialize the INI settings ;Traytip,%appname%, emailclient=%emailclient%`nmaxchar=%maxchar%,,1 Return OptionCancel: GoSub, 2GuiClose Return