Hotstrings suggestions popup list

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
omareg94
Posts: 94
Joined: 27 Jun 2016, 22:46

Hotstrings suggestions popup list

06 Dec 2017, 01:20

I'm using Texpand for android in order to expand text by inputting autotext.

Within Texpand, each phrase has a shortcut (hotstrings) and phrase (phrase to be expanded).

Let's say I have three phrases with these hotstrings
hotstring for phrase 1: hello,,phrase1,,hll,,h1
hotstring for phrase 2: hi,,phrase2,,hll,,h2
hotstring for phrase 3: welcome,,phrase3,,hll,,welcome,,h3

With AutoHotkey (per my knowledge), I need to type the whole hotstring (for example :*:hello,,phrase1,,hll,,h1::Phrase 1 Content ...) in order for the phrase to be expanded.
But with Texpand, I just need to type any portion of the hotstring, and phrases that their hotstring contains this sub-string will appear in the suggestions list menu.

Image
In Examples in screenshots:
1. When I input either "hll", "h3", or "ase3", I get a popup bubble telling me that there are phrases suggestions.
2. It opens a suggestions window of the phrases containing that portion I typed. When I tab any phrase, it's expanded like in 3.

Also Texpand sorts the phrases by the most used first (also the ones having the better match first).

How could I do the same thing with AutoHotkey?
  • How could I add suggestion popup window?
    Also, Knowing that I need to make detecting suggestions by inputting any portion of the hotstring.
What I need is to be able to type incomplete hotstrings, and AutoHotkey smartly shows me suggestions.
Current progress to achieve this:
Spoiler
Last edited by omareg94 on 06 Dec 2017, 18:17, edited 11 times in total.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: How to add suggestions popup window for phrases to be expanded using autotext?

06 Dec 2017, 02:17

So it appears you want hotstrings, but more dynamic.

It can be done. I don't know of the most efficient way, but I would use the Input command to capture typed text, compare it to registered shortcuts, and make the suggestion. How the suggestion is actually selected, I'm not sure - a GUI may be best.

Here is an example of matching it to registered shortcuts, using a tooltip instead of a GUI:

Code: Select all

^q::
var:="hll", possible_answers:=""

hello_shortcuts:="hello,phrase1,hll,h1"
hi_shortcuts:="hi,phrase2,hll,h2"
welcome_shortcuts:="welcome,phrase3,hll,h3"

If InStr(hello_shortcuts,var)
possible_answers.=hello_shortcuts "`n"
If InStr(hi_shortcuts,var)
possible_answers.=hi_shortcuts "`n"
If InStr(welcome_shortcuts,var)
possible_answers.=welcome_shortcuts "`n"
Tooltip % possible_answers
return
And here is condensed code that utilizes an array so we can put the If InStr() part into a loop:

Code: Select all

^q::
var:="hll", possible_answers:=""
hello_shortcuts:="hello,phrase1,hll,h1"
hi_shortcuts:="hi,phrase2,hll,h2"
welcome_shortcuts:="welcome,phrase3,hll,h3"
array:=[hello_shortcuts,hi_shortcuts,welcome_shortcuts]
Loop 3
   If InStr(array[A_Index],var)
        possible_answers.=array[A_Index] "`n"
Tooltip % possible_answers
return
change out var for "ase3" and only the welcome_shortcuts get shown.

This approach may not be ideal -- though I do think an array would be useful -- for making the dynamic output sent to the target program.

Hopefully this can get you thinking about how to handle the problem. I haven't followed through with the mental plan from start to finish, and the above is the only code I've actually practiced for this.
omareg94
Posts: 94
Joined: 27 Jun 2016, 22:46

Re: How to add suggestions popup window for phrases to be expanded using autotext?

06 Dec 2017, 13:35

@Exaskryz
I've added current progress of achieving this to the main post.
Last edited by omareg94 on 06 Dec 2017, 18:13, edited 3 times in total.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Expandable phrases suggestions popup window

06 Dec 2017, 15:00

This may not be what you need for this project, but just in case you didn't know, you don't need a "trigger" key to expand the phrase if you use an asterisk. For example, :*:wel::welcome will expand to "welcome" as soon as you press the 'l'.

As for problem number two, this should do it:

Code: Select all

Loop, 1000
  Hotkey, % "~*" GetKeyName(Format("sc{:x}", a_index - 1)), GetText

~Space::
  LastWord := Word
  Word := ""
return

~Backspace::Word := ""

GetText:
  Sleep, 50
  Key := RegExReplace(A_ThisHotkey, "^..")    	; "^.." removes the first 2 characters ("~*") from the returned string
  If StrLen(Key) = 1
  {
    If GetKeyState("Shift", "P")
      StringUpper, Key, Key
    Word .= Key
  }
Return
That logs each keystroke and stores the last word when you press Space.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Expandable phrases suggestions popup window

06 Dec 2017, 16:23

Here's a rough draft of a GUI that might suit your needs:

Code: Select all

Gui, AutoTextMenu:New, -Caption, AutoText Menu
Gui, AutoTextMenu:Add, Button, x0 y0 w200 h30 Default vOption1Var gOption1Sub
Gui, AutoTextMenu:Add, Button, x0 y30 w200 h30 vOption2Var gOption2Sub
Gui, AutoTextMenu:Add, Button, x0 y60 w200 h30 vOption3Var gOption3Sub
Gui, AutoTextMenu:Show, h90 w200, AutoText Menu
WinMove, AutoText Menu, , A_ScreenWidth - 200, A_ScreenHeight - 130
WinSet, AlwaysOnTop, On, AutoText Menu

; Creates a hotkey out of all keys so that it's known when each one is pressed
Loop, 1000
  Hotkey, % "~*" GetKeyName(Format("sc{:x}", a_index - 1)), GetText

~Space::
  LastWord := Word
  Word := ""
  GuiControl, AutoTextMenu:, Option1Var, %Word%
Return

GetText:
  Sleep, 50
  Key := RegExReplace(A_ThisHotkey, "^..")    	; "^.." removes the first 2 characters ("~*") from the returned string
  If StrLen(Key) = 1
  {
    If GetKeyState("Shift", "P")
      StringUpper, Key, Key
    Word .= Key
  }
  If Key = Backspace
    StringTrimRight, Word, Word, 1
  GuiControl, AutoTextMenu:, Option1Var, %Word%
Return

Option1Sub:
return

Option2Sub:
return

Option3Sub:
return
It doesn't do any substitution, just echos what you've typed, but it's a start.
omareg94
Posts: 94
Joined: 27 Jun 2016, 22:46

Re: Expandable phrases suggestions popup window

06 Dec 2017, 17:49

@Osprey #1:
I understand that ::*::by the way makes ending character not required.
There's a problem with this. We can't load hotstrings suggestions by typing just a part of the hotstrings.
What I need is to be able to type incomplete hotstrings, and AutoHotkey smartly shows me suggestions for potential phrases that I may need to expand.

I've edited the post for better language using AutoHotkey nomenclature. I'm sorry if it wasn't clear before.

I'm not with not using a trigger because I think it won't be efficient if I have a big database of hotstrings (~1000 phrases) that I need to search within every keystroke.

@Osprey #2:
I've played with it to support keystrokes and words being detected while phrases suggestions are shown simultaneously.

Code: Select all

; Creates a hotkey out of all keys so that it's known when each one is pressed
  Loop, 1000
    Hotkey, % "~*" GetKeyName(Format("sc{:x}", a_index - 1)), GetText

; Detects word endings
  ~Tab::
  ~Enter::
  ~Space::
    LastWord := Word
    GuiControl, AutoTextMenu:, Option1Var, %Word%
    Word := ""
  Return


GetText:
  Sleep, 50
  Key := RegExReplace(A_ThisHotkey, "^..")      ; "^.." removes the first 2 characters ("~*") from the returned string
  If StrLen(Key) = 1
  {
    If GetKeyState("Shift", "P")
      StringUpper, Key, Key
    Word .= Key
  }
  If Key = Backspace
    StringTrimRight, Word, Word, 1
  GuiControl, AutoTextMenu:, Option1Var, %Word%
  SearchText(Word)
Return

SearchText(Word) {
  hello_shortcuts:="hello,phrase1,hll,h1"
  hi_shortcuts:="hi,phrase2,hll,h2"
  welcome_shortcuts:="welcome,phrase3,hll,h3"

  var:= Word

  array:=[hello_shortcuts,hi_shortcuts,welcome_shortcuts]

  If (Word != "") {
    Loop 3
      If InStr(array[A_Index],var)
        possible_answers.=array[A_Index] "`n"

      ToolTip, % possible_answers, 100, 150
      possible_answers :=""
    Return
  }
}
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: Hotstrings suggestions popup list

17 Apr 2018, 12:06

omareg94,

Any more development on this? I was looking to create something similar.

Thank you,

arochon
omareg94
Posts: 94
Joined: 27 Jun 2016, 22:46

Re: Hotstrings suggestions popup list

01 May 2018, 20:35

arochon wrote:omareg94,

Any more development on this? I was looking to create something similar.

Thank you,

arochon
Hello arochon

Sorry for late reply.
Yes I've more updated version. I'm almost done with the GUI part.
I promise to upload my progress on GitHub, however, things need to be organised first.
Unfortunately I'm very busy with exams nowadays, so I expect to upload them within three weeks hopefully.
You're welcome to share any progress also.

Kind regards :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 313 guests