; Count characters as you type ; Date: 05/08/2007 ;Last Updated: 02/09/2007 ; Refer: hxxp://www.donationcoder.com/Forums/bb/index.php?topic=9420 FileInstall codythumbuprounded.png, codythumbuprounded.png FileInstall codytopcut.png, codytopcut.png #SingleInstance force #InstallKeybdHook #Persistent DetectHiddenWindows, On SetTitleMatchMode, 2 appname=Count-as-you-type ; to get a better name vernum=1.40 appdesc=This AHK-based program counts characters and words as you type them. INI_File=count.ini AutoStartFile=%A_Startup%\%appname%.lnk Gosub, Get_INI Gosub, MENU Gosub, Timer OnExit, ExitSub Return Get_DPI: 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=1 comments=%comments%`n`;%A_Tab%Microsoft Outlook=2 comments=%comments%`n`;%A_Tab%Outlook Express=3 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=3 ;default setting, as OE is available on every Win-machine quicksend=0 IniWrite,%maxchar%,%INI_File%,Settings,MaxChar IniWrite,%emailclient%,%INI_File%,Settings,EmailApp IniWrite,%quicksend%,%INI_File%,Settings,QuickSend IniWrite,%emailaddress%,%INI_File%,Settings,Recipient IniWrite,%autostart%,%INI_File%,Settings,AutoStart IniWrite,%guiontop%,%INI_File%,Settings,GuiOnTop IniWrite,%closetotray%,%INI_File%,Settings,CloseToTray IniWrite,%savepos%,%INI_File%,Settings,SavePos IniWrite,%notrayballoon%,%INI_File%,Settings,NoTrayBalloon IniWrite,%checkupdates%,%INI_File%,Settings,CheckUpdates } Else ;INI file exists, read from it { 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, IniRead,autostart,%INI_File%,Settings,AutoStart,0 IniRead,guiontop,%INI_File%,Settings,GuiOnTop,1 IniRead,closetotray,%INI_File%,Settings,CloseToTray,0 IniRead,savepos,%INI_File%,Settings,SavePos,0 IniRead,notrayballoon,%INI_File%,Settings,NoTrayBalloon,0 IniRead,checkupdates,%INI_File%,Settings,CheckUpdates,1 If autostart=1 { IfNotExist, %AutoStartFile% FileCreateShortcut, %A_ScriptFullPath%, %AutoStartFile%, %A_WorkingDir%,, %appdesc% } Else If autostart=0 { IfExist, %AutoStartFile% FileRecycle, %AutoStartFile% } If emailclient=1 { default_app=Mozilla Thunderbird emailwindow=Compose`: (no subject) } Else If emailclient=2 { default_app=Microsoft Outlook emailwindow=Untitled - Message } Else If emailclient=3 { default_app=Outlook Express emailwindow=New Message } } 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, active_id, ID, A ;for future use WinGet, emailwin_id, ID, %emailwindow% WinGetPos, X, Y, Width, Height, %emailwindow% MyX:=X+Width Gosub, APPGUI 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 If guiontop=1 Gui, +AlwaysOnTop Gosub, Get_DPI If dpi <> 96 Gui, Font,, Verdana Else Gui, Font, s10, Verdana Gui, Add, GroupBox, x336 y0 w115 h150, Gui, Add, GroupBox, x6 y150 w320 h55, Gui, Add, Picture, x337 y157 gSettings, codythumbuprounded.png If MeClose Gui, Add, Edit, gCountNow vCountNow x6 y10 w320 h140, %MeClose% Else Gui, Add, Edit, gCountNow vCountNow x6 y10 w320 h140, If quicksend=1 Gui, Add, Checkbox, x346 y120 w100 h20 Checked vToggleCheckBox gToggleCheckBox, Quick-Send Else Gui, Add, Checkbox, x346 y120 w100 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 Gui, Font, w200, Tahoma Gui, Add, Text, x346 y20 w100 h20, Character count: Gui, Add, Edit, vXCounter x346 y40 w40 h20 Number, Gui, Add, Text, vMaxTotal x386 y40 w64 h20, / %maxchar% Gui, Add, Text, x346 y70 w100 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 If savepos=1 { IniRead,posX,%INI_File%,Settings,posX IniRead,posY,%INI_File%,Settings,posY Gui, Show, x%posX% y%posY%, %appname% v%vernum% } Else Gui, Show, Center, %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% { If notrayballoon <> 1 TrayTip,%appname%, You have exceeded the maximum number of characters!,,2 ;Gui, Flash SoundPlay, %A_WinDir%\Media\ding.wav } Else If notrayballoon <> 1 TrayTip ;remove tray-tip ;Gui, Flash, Off Return ToggleCheckBox: Gui, Submit, NoHide 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 If allgood=1 { IfWinExist ahk_id %emailwin_id% { WinActivate, ahk_id %emailwin_id% ;quick hack for pasting into compose windows ;OE & Outlook - 3 tabs while Thunderbid - 2 tabs Send, {Tab 4} Send, ^v } Else { 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 If notrayballoon <> 1 TrayTip,%appname%,The new clipboard contents:`n%clipboard%.,,1 allgood=1 ;small boolean flag } Else If notrayballoon <> 1 TrayTip,%appname%,There is nothing to copy.,,1 Return ButtonClear: GuiControl, , Edit1, GoSub, CountNow Return GuiEscape: ClosetoTray: 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 ExitSub: WinGet, MaxGUI, MinMax, %appname% v%vernum% If MaxGUI=0 ;AHK gui not max'd or min'd If savepos=1 ; also if save last pos is check'd { WinGetPos, posX, posY, , , %appname% v%vernum% IniWrite,%posX%,%INI_File%,Settings,posX IniWrite,%posY%,%INI_File%,Settings,posY } ExitApp GuiClose: If closetotray=1 Gosub, GuiEscape Else GoSub, ExitSub Return QUIT: GoSub, ExitSub Return ;Configuration Window Settings: IfWinExist %appname% v%vernum% { If guiontop=1 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, Button, x100 y465 w90 h25 gOptionOk Default,OK Gui, 2:Add, Button, xp+100 y465 w90 h25 gOptionCancel,Cancel ; Gui, 2:Add, Tab, x6 y0 w380 h455, General||About| Gui, 2:Tab, General Gui, 2:Add, GroupBox, x20 y30 w350 h175, General Options ;--------------------------------------------------------- Gui, 2:Add, Checkbox, vAutoStart xp+12 yp+20 w325 h20, Start automatically with Windows. ;AutoStart Gui, 2:Add, Checkbox, vGuiOnTop yp+25 w325 h20, Always on top. ;GuiOnTop Gui, 2:Add, Checkbox, vCloseToTray yp+25 w325 h20, Minimize to system tray on close. ;CloseToTray Gui, 2:Add, Checkbox, vSavePos yp+25 w325 h20, Save last windows position when exiting. ;SavePos Gui, 2:Add, Checkbox, vNoTrayBalloon yp+25 w325 h20, Disable tray balloon. ;NoTrayBalloon Gui, 2:Add, Checkbox, vCheckUpdates yp+25 w325 h20 Disabled, Update via DCU feature? ;CheckUpdates Gui, 2:Add, GroupBox, x20 y210 w350 h65, Maximum Characters allowed ;--------------------------------------------------------- Gui, 2:Add, Text, xp+10 yp+25 w150 h20, Enter a number here: Gui, 2:Add, Edit, vNewMaxChar xp+150 yp w50 h20 Number Limit4, %maxchar% Gui, 2:Add, GroupBox, x20 y285 w350 h160, Programs to monitor: ;--------------------------------------------------------- Gui, 2:Add, Text, xp+12 yp+25 w230 h20,E-mail App: ;Gui, 2:Add, DropDownList, R3 xp+80 yp w220 h15, Mozilla Thunderbird |Microsoft Outlook |Outlook Express| If emailclient=1 Gui, 2:Add, DropDownList, AltSubmit vSelectedApp R3 xp+80 yp w220 h15, Mozilla Thunderbird ||Microsoft Outlook |Outlook Express| Else If emailclient=2 Gui, 2:Add, DropDownList, AltSubmit vSelectedApp R3 xp+80 yp w220 h15, Mozilla Thunderbird |Microsoft Outlook ||Outlook Express| Else If emailclient=3 Gui, 2:Add, DropDownList, AltSubmit vSelectedApp R3 xp+80 yp w220 h15, Mozilla Thunderbird |Microsoft Outlook |Outlook Express|| ;--------------------------------------------------------- Gui, 2:Add, Text, x32 yp+35 w230 h20,Custom Windows Title ;Gui, 2:Add, Edit, xp yp+20 w300 h22, Gui, 2:Add, Edit, xp yp+20 w300 h22 ReadOnly, Yet to be implemented. ; Gui, 2:Font, s8, MS San Serif, Verdana, Arial Gui, 2:Add, Text, xp yp+30 w300 h30, To add more than one program, split them with a pipe ( | ). Partial window titles are also supported. ;--------------------------------------------------------- ;Read from INI file & set the Options If autostart=1 GuiControl, 2:, AutoStart, 1 If guiontop=1 GuiControl, 2:, GuiOnTop, 1 If closetotray=1 GuiControl, 2:, CloseToTray, 1 If savepos=1 GuiControl, 2:, SavePos, 1 If notrayballoon=1 GuiControl, 2:, NoTrayBalloon, 1 If checkupdates=1 GuiControl, 2:, CheckUpdates, 1 ;--------------------------------------------------------- Gui, 2:Tab, About ;Gui, 2:Add, Picture, x15 y45, Cody-002.png Gui, 2:Add, Picture, x y+-1 Center, codytopcut.png Gui,2: Font, S14 Bold, Verdana Gui,2: Add, Text, xp+5 y+10 w340 Center, %appname% ;v%vernum% Gui, 2:Font, Norm Gui, 2:Font, s8, MS San Serif, Verdana, Arial Gui, 2:Add, Text, xm+5 y+5 w350, Requested by IconBoy. Additonal suggestions and feedback by Nod5, kiwi2b && ak_. Nod5 also helped out in code optimisation. The cool artwork was done by our resident Cody designer - nudone. Thanks to all of you and the rest of DC community (in case i had missed anyone). Gui, 2:Add, Text, xm+5 y+15,• Visit Gui, 2:Font, Cblue Underline, Gui, 2:Add, Text, x+5 yp gDC, DonationCoder.com Gui, 2:Font, CDefault Norm, Gui, 2:Add, Text, x+5 yp, for more cool tools. ; Gui, 2:Add, Text, xm+5 y+15,• For any comments or suggestions, click Gui, 2:Font, Cblue Underline, Gui, 2:Add, Text, x+5 yp gDC-Forum, here Gui, 2:Font, CDefault Norm, Gui, 2:Add, Text, xm+15 yp+15, to post in the forum thread. ;Gui, 2:Add, Text, x95 y45 w275, This program provides real-time character and word count. This will come in handy for users who need type within the given limit. For any comments or suggestions, please visit DonationCoder.com and post in the forum thread. ;Gui, 2:Add, Text, x15 y135 w365, Originally requested by IconBoy to be used with Outlook Express but since then have been expanded to include other programs as well. Gui, 2:Font, Norm ; Gui, 2:Show, x335 y181 w395 h500, Configuration Return DC: Run, http://www.donationcoder.com/ Return DC-Forum: Run, http://www.donationcoder.com/Forums/bb/index.php?topic=9420.new#new Return 2GuiClose: IfWinExist %appname% v%vernum% { If guiontop=1 WinSet,AlwaysOnTop,On, %appname% v%vernum% } Gui, 2:Destroy Return OptionOk: Gui, 2:Submit IfNotEqual, maxchar, %NewMaxChar% { maxchar=%NewMaxChar% ;Write settings to INI file IniWrite,%maxchar%,%INI_File%,Settings,MaxChar GuiControl, 1:, MaxTotal, / %maxchar% } Iniwrite, %SelectedApp%,%INI_File%,Settings,EmailApp ;emailclient:=SelectedApp-1 ;--------------------------------------------------------- IniWrite,%autostart%,%INI_File%,Settings,AutoStart IniWrite,%guiontop%,%INI_File%,Settings,GuiOnTop IniWrite,%closetotray%,%INI_File%,Settings,CloseToTray IniWrite,%savepos%,%INI_File%,Settings,SavePos IniWrite,%notrayballoon%,%INI_File%,Settings,NoTrayBalloon IniWrite,%checkupdates%,%INI_File%,Settings,CheckUpdates ;--------------------------------------------------------- If savepos=1 { WinGetPos, posX, posY, , , %appname% v%vernum% IniWrite,%posX%,%INI_File%,Settings,posX IniWrite,%posY%,%INI_File%,Settings,posY } Gosub, Get_INI ;re-initialize the INI settings ;Traytip,%appname%, emailclient=%emailclient%`nmaxchar=%maxchar%,,1 Return OptionCancel: GoSub, 2GuiClose Return