AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Intellisense-like autoreplacement with multiple suggestions
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
kakarukeys



Joined: 28 Sep 2009
Posts: 86

PostPosted: Wed Dec 23, 2009 2:18 pm    Post subject: Reply with quote

Anonymous wrote:
I think it's faster to use the arrow key when the item is near the top and near the bottom than have to look for the number. I like the arrow feature added not replace the tapping.


i see, but to implement the feature we need to replace the tooltip by a popup window Smile and set some hotkeys and event handlers. Quite a time-consuming task.
_________________
TypingAid autocompletion program made with AHK.
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Dec 23, 2009 4:07 pm    Post subject: Reply with quote

OK.
Back to top
maniac



Joined: 28 Aug 2009
Posts: 267

PostPosted: Wed Dec 23, 2009 4:34 pm    Post subject: Reply with quote

kakarukeys, did the c-bowl character work with the original script?
Back to top
View user's profile Send private message
kakarukeys



Joined: 28 Sep 2009
Posts: 86

PostPosted: Thu Dec 24, 2009 4:06 am    Post subject: Reply with quote

maniac wrote:
kakarukeys, did the c-bowl character work with the original script?


Sad No. I tried.
Do you have any possible work-around in mind? or we just have to wait for AutoHotKey to support the unicode character set.

I found the solution to No. 4. The font of tooltip can be adjusted in Control Panel.

Windows XP
1. Right click on Desktop, click Properties
2. Open the Appearance tab.
3. Click the Advanced button.
4. Pull down the list element and then select the item Tooltip.
5. Then select the new size of the text of tooltips in the Size list, 10 for example. Note that the default size is 8.
6. Finally, click OK.

Windows 7
1. Right click on Desktop, click Personalize
2. Click Display in 'See Also'
3. In "Make it easier to read what's on your screen", select 125% and apply.
4. you need to log off and log on again to see the changes
(This changes all text size, Windows 7 does not seem to allow individual change to tooltip font size)

Windows Vista
http://www.vista4beginners.com/How-to-change-font-size
(This changes all text size, Windows Vista also does not seem to allow individual change to tooltip font size)
_________________
TypingAid autocompletion program made with AHK.
Back to top
View user's profile Send private message
maniac



Joined: 28 Aug 2009
Posts: 267

PostPosted: Mon Dec 28, 2009 12:10 pm    Post subject: Reply with quote

Oh well, that stinks.

No, I have no other work-around in mind. I'm pretty sure we'd have to wait for AHK to support unicode, although someone who is more familiar with AHK than I am would be able to answer that better than me.

Nice, I didn't even think of looking at the Windows settings.

You can still get to the appearance tab in Vista/7, it's just a bit more buried. I'm going off the top of my head here as I'm on an XP machine right now, but go to the "Window Color and Appearance" page on the Personalize menu, then choose "Open classic appearance properties for more color options". You should be able to change the tooltip font size there.


Last edited by maniac on Mon Dec 28, 2009 12:16 pm; edited 1 time in total
Back to top
View user's profile Send private message
maniac



Joined: 28 Aug 2009
Posts: 267

PostPosted: Mon Dec 28, 2009 4:42 pm    Post subject: Reply with quote

maniac wrote:
You can still get to the appearance tab in Vista/7, it's just a bit more buried. I'm going off the top of my head here as I'm on an XP machine right now, but go to the "Window Color and Appearance" page on the Personalize menu, then choose "Open classic appearance properties for more color options". You should be able to change the tooltip font size there.


Oh, this will actually cause one problem. The tooltip text size is assumed to be a certain height, I don't actually check the registry. This is used to determine whether to display the ToolTip below the text or above it. It would have to be updated to check the registry.
Back to top
View user's profile Send private message
kakarukeys



Joined: 28 Sep 2009
Posts: 86

PostPosted: Fri Jan 01, 2010 1:25 pm    Post subject: Reply with quote

maniac wrote:
maniac wrote:
You can still get to the appearance tab in Vista/7, it's just a bit more buried. I'm going off the top of my head here as I'm on an XP machine right now, but go to the "Window Color and Appearance" page on the Personalize menu, then choose "Open classic appearance properties for more color options". You should be able to change the tooltip font size there.


Oh, this will actually cause one problem. The tooltip text size is assumed to be a certain height, I don't actually check the registry. This is used to determine whether to display the ToolTip below the text or above it. It would have to be updated to check the registry.


Confused I spent a long time and found where the appearance tab is in Vista/7, only to discover it doesn't adjust the tooltip size at all. Actually there are 2 kinds of tooltips in Vista/7. First kind is of shiny, silvery background, you get it by hovering over some icons on Desktop. Second is of light yellow background, you get it by hovering over the minimize, maximize, close boxes. The tooltip font option only affects the second kind.

Looks like Microsoft changed their software engineers since XP, and the older batch never told the newer batch about what they did.
_________________
TypingAid autocompletion program made with AHK.
Back to top
View user's profile Send private message
maniac



Joined: 28 Aug 2009
Posts: 267

PostPosted: Fri Jan 01, 2010 4:41 pm    Post subject: Reply with quote

kakarukeys wrote:
maniac wrote:
maniac wrote:
You can still get to the appearance tab in Vista/7, it's just a bit more buried. I'm going off the top of my head here as I'm on an XP machine right now, but go to the "Window Color and Appearance" page on the Personalize menu, then choose "Open classic appearance properties for more color options". You should be able to change the tooltip font size there.


Oh, this will actually cause one problem. The tooltip text size is assumed to be a certain height, I don't actually check the registry. This is used to determine whether to display the ToolTip below the text or above it. It would have to be updated to check the registry.


Confused I spent a long time and found where the appearance tab is in Vista/7, only to discover it doesn't adjust the tooltip size at all. Actually there are 2 kinds of tooltips in Vista/7. First kind is of shiny, silvery background, you get it by hovering over some icons on Desktop. Second is of light yellow background, you get it by hovering over the minimize, maximize, close boxes. The tooltip font option only affects the second kind.

Looks like Microsoft changed their software engineers since XP, and the older batch never told the newer batch about what they did.

LOL, how surprising Rolling Eyes
Back to top
View user's profile Send private message
maniac



Joined: 28 Aug 2009
Posts: 267

PostPosted: Mon Jan 04, 2010 8:09 pm    Post subject: Reply with quote

OK, I got around to getting my version back to a generic version - there are a LOT of changes (I did not thoroughly test that everything worked after stripping my custom code out, please let me know if you see any issues):

Changed the 10th item to number 0 rather than number 10 in the dropdown.

Changed the way the script waits for a window to be active again.

Added a workaround for an AHK bug which could cause keypresses to be interspersed in the autocompleted word.

Cleaned up code and reduced use of variables internally.

Words that you type will now be remembered and pop up at the end of the list until the script is restarted. If the words are typed more than 5x they will be remembered permanently and appended below a keyword ;LEARNEDWORDS;. They are ranked by typing frequency.

Tooltip now disappears when the line is changed (the word is NOT cleared).

Script:
Code:
;  Intellitype: typing aid
;  Press 1 to 0 keys to autocomplete the word upon suggestion
;  (0 will match suggestion 10)
;                                  - Jordi S
;                               Heavily modified by:
;                               Maniac
;___________________________________________

;    CONFIGURATIONS

; Editor Window Recognition
; (make it blank to make the script seek all windows)

OnExit, SaveScript
ETitle =

;Minimum word length to make a guess
WLen = 3
keyagain=
key=
clearword=1
;Gosub,clearallvars   ; clean vars from start

; Press 1 to 0 keys to autocomplete the word upon suggestion
; (0 will match suggestion 10)
;_______________________________________

CoordMode, ToolTip, Relative
AutoTrim, Off

WordListDone = 0
;reads list of words from file
Loop, Read,  %A_ScriptDir%\Wordlist.txt   
{
   addword = %a_loopreadline%
   Gosub, addwordtolist
}
SetTimer, Winchanged, 100
GoSub, ReverseWordNums
WordlistDone = 1

Loop
{
   ;Editor window check
    WinGetActiveTitle, ATitle
    WinGet, A_id, ID, %ATitle%
    IfNotInString, ATitle, %ETitle%
    {
      ToolTip
      Setenv, Word,
      WinWaitActive, %ETitle%
      Continue
  }
   
   ;Get one key at a time
   Input, chr, L1 V,{enter}{space}.;`,:¿?¡!'"()]{}{}}{bs}{{}{esc}{tab}{Home}{End}{PgUp}{PdDn}{Up}{Dn}{Left}{Right}
   EndKey = %errorlevel%
   ; If active window has different window ID from before the input, blank word
   ; (well, assign the number pressed to the word)   
   WinGetActiveTitle, ATitle
   WinGet, A_id2, ID, %ATitle%
   IfNotEqual, A_id, %A_id2%
   {
      Gosub,clearallvars
      Setenv, Word, %chr%
      Continue
   }
   
   ifequal, OldCaretY,
        OldCaretY = %A_CaretY%
   ifnotequal, OldCaretY, %A_CaretY%
   {
      ; add the word if switching lines
      addword = %Word%
      Gosub, addwordtolist
         Gosub,clearallvars
         Setenv, Word, %chr%
         Continue
         
   }
   
   OldCaretY=%A_CaretY%
   
      ;Backspace clears last letter
   ifequal, EndKey, Endkey:BackSpace
   {
      StringLen, len, Word
      IfNotEqual, len, 0
      {
         ifequal, len, 1   
         {
            Gosub,clearallvars
         } else {
                  StringTrimRight, Word, Word, 1
                }     
      }
   } else ifequal, EndKey, Max
         {
            Setenv, Word, %word%%chr%
         } else {
                  addword = %Word%
                  Gosub, addwordtolist
                  Gosub, clearallvars     
                }
   
   ;Wait till minimum letters
   IF ( StrLen(Word) < wlen )
   {
      ToolTip,
      Continue
   }
   
   ;Match part-word with command
   Num =
   Match =
   singlematch = 0
   number = 0
   StringLeft, baseword, Word, %wlen%
   baseword := ConvertWordToAscii(baseword,1)
   Loop
   {
      IfEqual, zword%baseword%%a_index%,, Break
      IfEqual, number, 10
         Break
      if ( SubStr(zword%baseword%%a_index%, 1, StrLen(Word)) = Word )
      {
         number ++
         singlematch := zword%baseword%%a_index%
         match := match . Mod(number,10) . ". " . singlematch . "`n"
         singlematch%number% = %singlematch%
           
         Continue           
      }
   }
   
   ;If no match then clear Tip
   IfEqual, Match,
   {
      clearword=0
      Gosub,clearallvars
      Continue
   }
   
   ;Show matched command
   StringTrimRight, match, match, 1        ; Get rid of the last linefeed
   WinGetActiveTitle, ATitle
   WinGetPos, , PosY, , SizeY, %ATitle%
   ToolTipSizeY := (number * 12)
   ToolTipPosY := A_CaretY+14
   if ((ToolTipSizeY + ToolTipPosY) > (PosY + SizeY))
       ToolTipPosY := (A_CaretY - 14 - ToolTipSizeY)
   IfNotEqual, Word,,ToolTip, %match%, %A_CaretX%, %ToolTipPosY%
   ; +14 Move tooltip down a little so as not to hide the caret.
}

; Timed function to detect change of focus (and remove tooltip when changing active window)
Winchanged:
   WinGetActiveTitle, ATitle
   WinGet, A_id3, ID, %ATitle%
   IfNotEqual, A_id, %A_id3%
   {
      ToolTip ,
   } else {
            ; If we are in the correct window, and OldCaretY is set, clear the tooltip if not in the same line
            IfInString, ATitle, %ETitle%
            {
               IfNotEqual, OldCaretY,
               {
                  IfNotEqual, OldCaretY, %A_CaretY%   
                  {
                     ToolTip,
                  }
               }
            }
         }
   Return
   
; Key definitions for autocomplete (0 to 9)
#MaxThreadsPerHotkey 1
$1::
key=1
Gosub, checkword
Return

$2::
key=2
Gosub, checkword
Return

$3::
key=3
Gosub, checkword
Return

$4::
key=4
Gosub, checkword
Return

$5::
key=5
Gosub, checkword
Return

$6::
key=6
Gosub, checkword
Return

$7::
key=7
Gosub, checkword
Return

$8::
key=8
Gosub, checkword
Return

$9::
key=9
Gosub, checkword
Return

$0::
key=10
Gosub, checkword
Return


; If hotkey was pressed, check wether there's a match going on and send it, otherwise send the number(s) typed
checkword:
   clearword=1

   ; If active window has different window ID from before the input, blank word
   ; (well, assign the number pressed to the word)
   WinGetActiveTitle, ATitle
   WinGet, A_id2, ID, %ATitle%
   IfNotEqual, A_id, %A_id2%
      {
         if key =10
            key = 0
         BlockInput, On
         SendInput,%key%
         BlockInput, Off
         Gosub,clearallvars
         Return
      }
     
   IfNotEqual, OldCaretY, %A_CaretY% ;Make sure we are still on the same line
      {
         if key =10
            key = 0
         BlockInput, On
         SendInput,%key%
         BlockInput, Off
         Gosub,clearallvars
         Return
      }

   ifequal, Word,        ; only continue if word is not empty
   {
      if key =10
         key = 0
      BlockInput, On
      SendInput,%key%
      BlockInput, Off
      Setenv, Word, %key%
      clearword=0
      Gosub,clearallvars
      Return
   }
   
   ifequal, singlematch%key%,   ; only continue singlematch is not empty
      {
         if key =10
            key = 0
         BlockInput, On
         SendInput,%key%
         BlockInput, Off
         Setenv, Word, %word%%key%
         clearword=0
         Gosub,clearallvars
         Return
      }

   ; SEND THE WORD!
   if key =0
      key = 10
   sending := singlematch%key%
   StringLen, len, Word
   ; Update Typed Count
   UpdateWordCount(sending)   
   BlockInput, On
   SendInput, {BS %len%}{Raw}%sending% ; First do the backspaces, Then send word (Raw because we want the string exactly as in wordlist.txt)
   BlockInput, Off
   Gosub,clearallvars
   Return


; This is to blank all vars related to matches, tooltip and (optionally) word
clearallvars:
      Ifequal,clearword,1
      {
         Setenv,word,   
         OldCaretY=
      }
      ToolTip
      ; Clear all singlematches
      Loop, 10
      {
         singlematch%a_index% =
      }
      sending =
      key=
      match=
      clearword=1
      Return
;expects a value in addword
addwordtolist:
   Ifequal, Addword,  ;If we have no word to add, skip out.
      Return
   if ( Substr(addword,1,1) = ";" ) ;If first char is ";", clear word and skip out.
   {
      IfEqual, wordlistdone, 0 ;If we are still reading the wordlist file and we come across ;LEARNEDWORDS; set the LearnedWordsCount flag
      {
         IfEqual, AddWord, `;LEARNEDWORDS`;
            LearnedWordsCount=0
      }
      addword =
      Return
   }
   ifequal, wordlistdone, 1 ;if we are not reading the wordlist file, use the following characters in the terminate list
         CharTerminateList = 1,2,3,4,5,6,7,8,9,0
   else CharTerminateList =
   if addword contains %CharTerminateList% ;if one of the chars in the word is in the terminate list, don't add it
   {
      addword =
      CharTerminateList =
      Return
   }
   CharTerminateList =
   IF ( StrLen(addword) <= wlen ) ; don't add the word if it's not longer than the minimum length
   {
      addword =
      Return
   }

   Base := ConvertWordToAscii(SubStr(addword,1,wlen),1)
   AddWordInList =
   Loop ;Check to see if the word is already in the list, case sensitive
   {
      IfEqual, zword%base%%a_index%,, Break
      if ( zword%base%%a_index% == Word )
      {
         AddWordInList = 1
         Break
      }           
      Continue           
   }
     
   ifequal, AddWordInList,   ; if the word is not in the list
   {
      IfEqual, WordListDone, 0 ;if this is read from the wordlist
      {
         IfNotEqual,LearnedWordsCount,  ;if this is a stored learned word
         {
            CountWord := ConvertWordToAscii(addword,0)
            IfEqual, LearnedWords,     ;if we haven't learned any words yet, set the LearnedWords list to the new word
            {
               LearnedWords = %addword% 
            } else {   ;otherwise append the learned word to the list
                     LearnedWords = %LearnedWords%,%addword%
                  }
            zCount%CountWord% := LearnedWordsCount++    ;increment the count and store the Weight of the LearnedWord in reverse order (will be inverted later)
         }
      } else {    ; If this is an on-the-fly learned word
               CountWord := ConvertWordToAscii(addWord,0)
               zCount%CountWord% = 1   ;set the count to one as it's the first time we typed it
               IfEqual, LearnedWords,    ;if we haven't learned any words yet, set the LearnedWords list to the new word
               {
                  LearnedWords = %addword% 
               } else {   ;otherwise append the learned word to the list
                        LearnedWords = %LearnedWords%,%addword%
                     }
            }
      ; Increment the counter for each hash
      zbasenum%Base%++       
      pos := zbasenum%Base%
      ; Set the hashed value to the word
      zword%Base%%pos% = %addword%
      pos =
   } Else {
            IfEqual, WordListDone, 1   ;if we've already typed the word and we've loaded the wordlist increment the count
            {
               UpdateWordCount(addword)
            }
         }
   
   CountWord =
   AddWordInList =
   addword =
   Base =
   Return
   
; This sub will reverse the read numbers since now we know the total number of words
ReverseWordNums:
LearnedWordsCount+=4
Loop,parse,LearnedWords, `,
{
   AsciiWord := ConvertWordToAscii(A_LoopField,0)
   zCount%AsciiWord% := LearnedWordsCount - zCount%AsciiWord%
}

AsciiWord =
LearnedWordsCount =

Return

UpdateWordCount(word)
{
; If the Count for the word already exists - ie if it's a learned word, increment it, else don't.
   local CountWord := ConvertWordToAscii(word,0)
   IfNotEqual, zCount%CountWord%,
   {
      zCount%CountWord%++ 
      local WordBase
      StringLeft, WordBase, word, %wlen% ;find the pseudohash for the word
      WordBase := ConvertWordToAscii(WordBase,1)
      Local ConvertWord =
      Local LowIndex =
      Local WordList =
      Loop
      {
         ifequal, zword%WordBase%%A_Index%, ;Break the loop if no more words to read for the hash
            Break
         CountWord := zword%WordBase%%A_Index% ;Set CountWord to the current Word position
         ConvertWord := ConvertWordToAscii(CountWord,0) ; Find the Ascii equivalent of the word
         IfNotEqual, zCount%ConvertWord%,  ;If there's no count for this word do nothing
         {
            IfEqual, LowIndex,
               LowIndex = %A_Index% ;If this is the first word we've found with a count set this as our starting position
           
            IfEqual, WordList,  ;if we have no words in our wordlist, start it - prefix all words with (Count"z")
            {
               WordList := zCount%ConvertWord% . "z" . CountWord
            } Else {  ;else append to the wordlist
                     WordList := WordList . "," . zCount%ConvertWord% . "z" . CountWord
                  }
         }
      }
     
      ifnotequal, Wordlist, ;If we have no words to process, don't
      {
         Sort, WordList, N R D, ;Sort the wordlist by order of
         
         LowIndex-- ;A_Index starts at 1 so this value needs to be decremented
         Local IndexPos =
         Loop, Parse, WordList, `,
         {
            IndexPos := LowIndex + A_Index ;Set the current word we are processing to the starting pos plus word position
            StringTrimLeft, CountWord, A_LoopField, InStr(A_LoopField,"z") ;Strip (Number,"z") from beginning
            zword%WordBase%%IndexPos% = %CountWord% ; update the word in the list
           
         }
      }
   }
   Return
}
     
ConvertWordToAscii(Base,Caps)
{
; Return the word in Ascii numbers padded to length 3 per character
; Capitalize the string if NoCaps is not set
   IfEqual, Caps, 1
      StringUpper, Base, Base
   Loop, % StrLen(Base)
   {
      New := New . PadZeros(Asc(Base),3)
      StringTrimLeft, Base, Base, 1
   }
Return New
}

PadZeros(Word,Length)
{
; Pad a string out to Length numbers of 0's
   StringLen, WordLen, Word
   IfLess, WordLen, Length
   {
      Loop, % (Length - WordLen)
      {
         Word := "0" . Word
      }
   }
Return Word
}     
   
SaveScript:
; Delete the Temp_Wordlist if it exists
FileDelete, %A_ScriptDir%\Temp_WordList.txt
; Add all the standard words to the tempwordlist
Loop, Read, %A_ScriptDir%\Wordlist.txt, %A_ScriptDir%\Temp_WordList.txt
{
   IfEqual, A_LoopReadLine, `;LEARNEDWORDS`;
      SkipRest = 1
   IfEqual, SkipRest,
      FileAppend, %A_LoopReadLine%`n
}
; Parse the learned words and store them in a new list by count if their total count is greater than 5.
; Prefix the word with the count and "z" for sorting
Loop, Parse, LearnedWords, `,
{
   SortWord := ConvertWordToAscii(A_LoopField,0)
   
   IfGreaterOrEqual, zCount%SortWord%, 5
   {
      IfEqual, SortWordList,
      {
         SortWordList := zCount%SortWord% . "z" . A_LoopField
      } else {
               SortWordList := SortWordList . "," . zCount%SortWord% . "z" . A_LoopField
            }
   }
}

Sort, SortWordList, N R D, ; Sort numerically, comma delimiter

IfNotEqual, SortWordList, ; If SortWordList exists write to the file, otherwise don't.
{
   FileAppend, `;LEARNEDWORDS`;`n, %A_ScriptDir%\Temp_WordList.txt

   FirstTimeLoop = 1
   Loop, Parse, SortWordList, `,
   {
      StringTrimLeft, AppendWord, A_LoopField, InStr(A_LoopField,"z") ;Strip (Number,"z") from beginning
      IfEqual, FirstTimeLoop,  ;If we are not in our first time through the loop append a new line before the word
      {
         AppendWord = `n%AppendWord%
      } else {
               FirstTimeLoop =
            }
      FileAppend, %AppendWord%, %A_ScriptDir%\Temp_WordList.txt
   }

   FileCopy, %A_ScriptDir%\Temp_WordList.txt, %A_ScriptDir%\WordList.txt, 1 ;Only update the file if we have learned words

}

FileDelete, %A_ScriptDir%\Temp_WordList.txt ;Delete the Tempwordlist as we no longer need it

ExitApp
Back to top
View user's profile Send private message
Guest






PostPosted: Tue Jan 05, 2010 2:39 am    Post subject: Reply with quote

waiting and hoping for the arrow feature. Wink
Back to top
kakarukeys



Joined: 28 Sep 2009
Posts: 86

PostPosted: Tue Jan 05, 2010 2:56 am    Post subject: Reply with quote

Very Happy Good timing.
I just figured out how to detect caret in applications that don't support win32api's GetCaretPos() such as Firefox.
Let's me see how to merge some of the changes in old code into the new one
_________________
TypingAid autocompletion program made with AHK.
Back to top
View user's profile Send private message
maniac



Joined: 28 Aug 2009
Posts: 267

PostPosted: Tue Jan 05, 2010 5:01 am    Post subject: Reply with quote

kakarukeys wrote:
Very Happy Good timing.
I just figured out how to detect caret in applications that don't support win32api's GetCaretPos() such as Firefox.
Let's me see how to merge some of the changes in old code into the new one

What are you using to get the Caret in Firefox/Thunderbird?
Back to top
View user's profile Send private message
kakarukeys



Joined: 28 Sep 2009
Posts: 86

PostPosted: Wed Jan 06, 2010 3:26 am    Post subject: Reply with quote

maniac wrote:
kakarukeys wrote:
Very Happy Good timing.
I just figured out how to detect caret in applications that don't support win32api's GetCaretPos() such as Firefox.
Let's me see how to merge some of the changes in old code into the new one

What are you using to get the Caret in Firefox/Thunderbird?


Rolling Eyes a 'psychological hack'. I checked ClipX, a clipboard program which also has popup at caret position. It doesn't popup correctly in Firefox, the author chose to popup at mouse cursor position which can be any distance away from caret. Then I thought last-mouse-click position should be a better approximation, since the user usually clicks inside the edit control before typing. Here are the modifications, it works well when the edit control is small such as a search box or a text area such as what I'm typing inside now. So we have (1) - wait, (2) - hack, (3) - fixed, (4) - partial solution.

Code:
;  Typing aid
;  Press 1 to 0 keys to autocomplete the word upon suggestion
;  (0 will match suggestion 10)
;                                  - Jordi S
;                               Heavily modified by:
;                                  - Maniac
;                               modified by:
;                                  - Asaptrad
;                                  - Artwinauto.com
;___________________________________________

SplashTextOn,400,100,,TypingAid Program version 1.2 from Artwinauto.com. Credits: Jordi S, Maniac, Asaptrad @ AutoHotKey Forum
Sleep, 3000
SplashTextOff

;    CONFIGURATIONS

; Editor Window Recognition
; (make it blank to make the script seek all windows)

ETitle =

;Minimum word length to make a guess
WLen = 3
keyagain=
key=
clearword=1
MouseX = 0
MouseY = 0
;Gosub,clearallvars   ; clean vars from start

; Press 1 to 0 keys to autocomplete the word upon suggestion
; (0 will match suggestion 10)
;_______________________________________

CoordMode, ToolTip, Relative
CoordMode, Mouse, Relative
AutoTrim, Off

;reads list of words from file
Loop, Read,  %A_ScriptDir%\Wordlist.txt   
{
   StringLeft, Base, a_loopreadline, %wlen%
   Base := ConvertWordToAscii(Base)
   basenum%Base%++
   pos := basenum%Base%
   cmd%Base%%pos% = %a_loopreadline%
}
SetTimer, Winchanged, 100

Loop
{
   ;Editor window check
    WinGetActiveTitle, ATitle
    WinGet, A_id, ID, %ATitle%
    IfNotInString, ATitle, %ETitle%
    {
      ToolTip
      Setenv, Word,
      sleep, 500
      Continue
  }
   
   ;Get one key at a time
   Input, chr, L1 V,{enter}{space}.;`:¿?¡!()]{}{}}{bs}{{}{esc}{tab}{Home}{End}{PgUp}{PdDn}{Up}{Dn}{Left}{Right}
   EndKey = %errorlevel%
   ; If active window has different window ID from before the input, blank word
   ; (well, assign the number pressed to the word)   
   WinGetActiveTitle, ATitle
   WinGet, A_id2, ID, %ATitle%
   IfNotEqual, A_id, %A_id2%
   {
      Gosub,clearallvars
      Setenv, Word, %chr%
      Continue
   }
   
   ifequal, OldCaretY,
        OldCaretY = HCaretY()
   ifnotequal, OldCaretY, HCaretY()
   {
         Gosub,clearallvars
         Setenv, Word, %chr%
         Continue
         
   }
   
   OldCaretY=HCaretY()
   
      ;Backspace clears last letter
      ifequal, EndKey, Endkey:BackSpace
      {
        StringLen, len, Word
        IfNotEqual, len, 0
         { ifequal, len, 1
            {
            Gosub,clearallvars
            } else {
                     StringTrimRight, Word, Word, 1
                   }     
         }
   } else ifequal, EndKey, Max
         {
         ifequal, chr, @
                  {
                     Gosub,clearallvars
                     Setenv, Word, %chr%
                     Continue
                  } else {
                           Setenv, Word, %word%%chr%
                           }
            } else Gosub,clearallvars
   
   ;Wait till minimum letters
   StringLen, len, Word
   IfLess, len, %wlen%
   {
      ToolTip
      Continue
   }
   
   ;Match part-word with command
   Num =
   Match =
   singlematch = 0
   number = 0
   StringLeft, baseword, Word, %wlen%
   baseword := ConvertWordToAscii(baseword)
   Loop
   {
      IfEqual, cmd%baseword%%a_index%,, Break
      IfEqual, number, 10
         Break
      StringLen, chars, Word
      StringLeft, strippedcmd, cmd%baseword%%a_index%, %chars%
      ifequal, strippedcmd, %Word%
      {
            number ++
            singlematch := cmd%baseword%%a_index%
            match := match . Mod(number,10) . ". " . singlematch . "`n"
            singlematch%number% = %singlematch%
           
            Continue           
      }
}
   ;If no match then clear Tip
   IfEqual, Match,
   {
      clearword=0
      Gosub,clearallvars
      Continue
   }
   
   ;Show matched command
   StringTrimRight, match, match, 1        ; Get rid of the last linefeed
   WinGetActiveTitle, ATitle
   WinGetPos, , PosY, , SizeY, %ATitle%
   MaxY := PosY + SizeY
   ToolTipSizeY := (number * 12)
   ToolTipPosY := HCaretY()+24
   if ((ToolTipSizeY + ToolTipPosY) > MaxY)
       ToolTipPosY := (HCaretY() - 14 - ToolTipSizeY)
   IfNotEqual, Word,,ToolTip, %match%, HCaretX(), %ToolTipPosY%
   ; +14 Move tooltip down a little so as not to hide the caret.
}

; Timed function to detect change of focus (and remove tooltip when changing active window)
Winchanged:
   WinGetActiveTitle, ATitle
   WinGet, A_id3, ID, %ATitle%
   IfNotEqual, A_id, %A_id3%
   {
      ToolTip ,
   } else {
            ; If we are in the correct window, and OldCaretY is set, clear the tooltip if not in the same line
            IfInString, ATitle, %ETitle%
            {
               IfNotEqual, OldCaretY,
               {
                  IfNotEqual, OldCaretY, HCaretY()
                  {
                     ToolTip,
                  }
               }
            }
         }
   Return
   
; Key definitions for autocomplete (0 to 9)
#MaxThreadsPerHotkey 1
$1::
key=1
Gosub, checkword
Return

$2::
key=2
Gosub, checkword
Return

$3::
key=3
Gosub, checkword
Return

$4::
key=4
Gosub, checkword
Return

$5::
key=5
Gosub, checkword
Return

$6::
key=6
Gosub, checkword
Return

$7::
key=7
Gosub, checkword
Return

$8::
key=8
Gosub, checkword
Return

$9::
key=9
Gosub, checkword
Return

$0::
key=10
Gosub, checkword
Return

^+c::
text =
ClipBoard =
Sleep, 100
SendInput, ^c
Sleep, 200
text = %Clipboard%

found = 0

Loop, Read, wordlist.txt
{
   If text = %A_LoopReadLine%
   found = 1
}

If found = 0
FileAppend, %text%`n, wordlist.txt

Reload
Sleep 200

Return

~LButton::
MouseGetPos, MouseX, MouseY
Return

; If hotkey was pressed, check wether there's a match going on and send it, otherwise send the number(s) typed
checkword:
   clearword=1

   ; If active window has different window ID from before the input, blank word
   ; (well, assign the number pressed to the word)
   WinGetActiveTitle, ATitle
   WinGet, A_id2, ID, %ATitle%
   IfNotEqual, A_id, %A_id2%
      {
         if key =10
            key = 0
         SendInput,%key%
         Gosub,clearallvars
         Return
      }
     
   IfNotEqual, OldCaretY, HCaretY()
      {
         if key =10
            key = 0
         SendInput,%key%
         Gosub,clearallvars
         Return
      }

   if word=        ; only continue if word is not empty
      {
         if key =10
            key = 0
         SendInput,%key%
         Setenv, Word, %key%
         clearword=0
         Gosub,clearallvars
         Return
      }
   
   ifequal, singlematch%key%,   ; only continue singlematch is not empty
      {
         if key =10
            key = 0
         SendInput,%key%
         Setenv, Word, %word%%key%
         clearword=0
         Gosub,clearallvars
         Return
      }

   ; SEND THE WORD!
   if key =0
      key = 10
   sending := SubStr(singlematch%key%, len+1)
   StringLen, len, Word   
   SendInput, {Raw}%sending% ; Send word (Raw because we want the substring exactly as in wordlist.txt)
   
   Gosub,clearallvars
   Return


; This is to blank all vars related to matches, tooltip and (optionally) word
clearallvars:
      Ifequal,clearword,1,Setenv,word,
      ToolTip
      ; Clear all singlematches
      Loop, 10
      {
         singlematch%a_index% =
      }
      sending =
      key=
      match=
      clearword=1
      OldCaretY=
      Return
     
ConvertWordToAscii(Base)
{
   StringUpper, Base, Base
   StringLen, Len, Base
   Loop, %Len%
   {
      Transform, Letter, Asc, %Base%
      StringLen, LetterLen, Letter
      IfLess, %LetterLen%, 3
      {
         Amt := 3-LetterLen
         Loop, %Amt%
         {
            Letter = 0%Letter%
         }
      }
      New = %New%%Letter%
      StringTrimLeft, Base, Base, 1
   }
Return New
}

HCaretX()
{
    global
    if A_CaretX < 7
    {
        if MouseX != 0
        {
            return MouseX - 50
        }
    }
    return A_CaretX
}

HCaretY()
{
    global
    if A_CaretX < 7
    {
        if MouseY != 0
        {
            return MouseY
        }
    }
    return A_CaretY
}


I tested your code. Sad and I got this error when trying to autocomplete the 2nd phrase below

Imagination is more important than knowledge.
Imagination will often carry us to worlds that never were. But without it we go nowhere.

Any idea?

_________________
TypingAid autocompletion program made with AHK.
Back to top
View user's profile Send private message
maniac



Joined: 28 Aug 2009
Posts: 267

PostPosted: Wed Jan 06, 2010 10:21 am    Post subject: Reply with quote

I see, but that won't work for large textboxes, couldn't that cover up what you are typing?

It was never intended for use with sentences to begin with. Can you try something? Add about 5 characters to that long line and see if it crashes the old TypingAid script.
Back to top
View user's profile Send private message
maniac



Joined: 28 Aug 2009
Posts: 267

PostPosted: Wed Jan 06, 2010 3:32 pm    Post subject: Reply with quote

Ah, I see why it's crashing. Yeah I guess that's going to happen when you use really long words - it's part of how it maintains the number of times you have typed a certain word. This is a limitation of AHK's array handling.

The limit appears to be 82 characters (+6 used by the "zCount" prefix). As such, I would not recommend using the learning version with phrases or sentences. However, this is enough to cover the longest official English word:
http://en.wikipedia.org/wiki/Longest_word_in_English
and even cover the longest official German word (copy and paste, phpBB doesn't like the umlaut):
http://en.wikipedia.org/wiki/Donaudampfschiffahrtselektrizitätenhauptbetriebswerkbauunterbeamtengesellschaft

Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
Page 3 of 10

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group