Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keyboard Shortcut - Get a Word Count of Selected Text
#1
Lightbulb 
Have you ever had to copy and paste text to Microsoft Word just to get a word count? If so, this AutoHotkey script may interest you. It counts how many words are in a selected portion of text (from a website, document, or other), pretty much like the Word Count function in MS Word.

The script counts the number of non-whitespace character groups. The count result is supposed to be the same as MS Word (2010) in English and French languages. So this script will count "It’s AutoHotkey-based" and "Bonjour !" as two words.

Need help creating a keyboard shortcut with ShortKeeper using the following AutoHotkey code? This 5-minute tutorial will help!
ClipSaved := ClipboardAll
Clipboard =
SendInput, ^c
ClipWait, 2
if ErrorLevel
{
  MsgBox % "Failed attempt to read selected text."
}
else
{
  NewClipboard := Trim(Clipboard)
  Count := 0
  Position := 1
  while, Position := RegExMatch(NewClipboard, "\S+", Out, Position+Strlen(Out))
    Count++
  MsgBox % "Words :" . Count
}
;Clipboard := ClipSaved

The script replaces the clipboard content with the selected text. The last line of code (#18) can be uncommented (delete ';' at the beginning of the line) to restore the clipboard with its previous content.

This script is optimized to be used with ShortKeeper. As such, there is no "Return" at the end and variable(s) don’t need to be cleared. ShortKeeper will do this automatically. Just copy/paste the code in the PARAM field in ShortKeeper, set your hotkey, save, and you’re ready to use your new keyboard shortcut.
Enterpad: For those who need more than a few shortcuts.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)