Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Smart Comboboxes


  • Please log in to reply
9 replies to this topic
philz
  • Members
  • 89 posts
  • Last active: Mar 02 2009 06:23 AM
  • Joined: 05 Jun 2007
by using the cmboxfill on a timed subrutine you can have the combobox fill in and highlight the rest of texts that you have preveously entered.

PRITTY COOL HUH

values = |0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111 ; a list of values to put in the combobox the first value should be preceded by a linefeed for cmboxfill to work
gui, add, combobox, w120 +vscroll r5 vcombo, %values%
gui, show
settimer, filly, 50
return



filly:
gui, submit, nohide
cmboxfill(values, combo)
return

cmboxfill(haystack, needle) ; help from toralf
{
   If (getkeystate("delete")  OR getkeystate("backspace") or (strlen(needle) > 0 ? 0 : 1))
      Return
   re =(\||^)\Q%needle%\E(?P<Rest>.*?)(\||$)
   regexmatch(haystack, re,Input)
   len := StrLen(InputRest)
   sendinput, %InputRest%{shift down}{left %len%}{shift up}
}


tab::   ;this subrutine is used to put in more values (the sort is not neccesary to the cmboxfill(x,y) function
enter::
gui, submit, nohide
ifnotinstring, values, %combo%
	values = %Values%|%combo%
sort, values, D|
guicontrol,,combo, |%values%
guicontrol, text, combo
return


guiclose:
exitapp
I had a lot of trouble putting this together (mostly because of not getting the darn thing to stop by pressing delete or backspace then getting it to restart by pressing any other key)

If you guys can think of any improovement to the function i would greatlyappreciate any comments.
So what do you think

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Here is a mod,
values = |0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111

gui, add, combobox, w120 +vscroll r5 vcombo gcombo, %values%

gui, show

return



combo:

gui, submit, nohide

If combo is not space

  cmboxfill(values, combo)

return



cmboxfill(haystack, needle){

   If (getkeystate("delete")  OR getkeystate("backspace"))

      Return

   re =\|\Q%needle%\E(?P<Rest>.*?)(\||$)

   regexmatch(haystack, re,Input)

   len := StrLen(InputRest)

   sendinput, %InputRest%{shift down}{left %len%}{shift up}

}



tab::

enter::

  gui, submit, nohide

  ifnotinstring, values, %combo%

     values = %Values%|%combo%

  sort, values, D|

  guicontrol,,combo, |%values%

  guicontrol, text, combo

return



guiclose:

  exitapp

Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

philz
  • Members
  • 89 posts
  • Last active: Mar 02 2009 06:23 AM
  • Joined: 05 Jun 2007
so is "(?P<Rest>.*?)" a look ahead assertion? and what is the purpose of "<rest>". is it used to tell that everything to the right of that string is "the rest", or is it used in the naming of inputrest?

ok nevermind i found it in the help file. thanks i like your method.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
RegEx is inefficient for this purpose, and it can be done so simply:

Gui, Add, ComboBox, vSel w120 r5 gAutoComplete, |0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111
Gui, Show, , Example
Return

AutoComplete:
If GetKeyState("Delete") or GetKeyState("Backspace")
	Return
SetControlDelay, -1
SetWinDelay, -1
GuiControlGet, h, Hwnd, %A_GuiControl%
ControlGet, haystack, List, , , ahk_id %h%
GuiControlGet, needle, , %A_GuiControl%
lf = `n
StringMid, text, haystack, pos := InStr(lf . haystack, lf . needle)
	, InStr(haystack . lf, lf, false, pos) - pos
If text !=
{
	ControlSetText, , %text%, ahk_id %h%
	ControlSend, , % "{Right " . StrLen(needle) . "}+^{End}", ahk_id %h%
}
Return

GuiClose:
ExitApp

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


philz
  • Members
  • 89 posts
  • Last active: Mar 02 2009 06:23 AM
  • Joined: 05 Jun 2007
I know that regexes are a bit slow but i am in the process of creating a gui with multiple (about 20) comboboxes with this property and i didn't want all all the global variables. i also like the modularity of this function.

I have adapted it from what toralf made so it doesnt require the list of values to begin with a pipe character, and so that the function dosent completely run if the combobox is blank.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
If you don't like globals you can use a function like this, and cache values:

Gui, Add, ComboBox, vSel w120 r5 gAC, |0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111
Gui, Show, , Example
Return

AC:
AutoComplete(A_GuiControl)
Return

AutoComplete(ctrl) {
	static lf = "`n"
	If GetKeyState("Delete") or GetKeyState("Backspace")
		Return
	SetControlDelay, -1
	SetWinDelay, -1
	GuiControlGet, h, Hwnd, %ctrl%
	ControlGet, haystack, List, , , ahk_id %h%
	GuiControlGet, needle, , %ctrl%
	StringMid, text, haystack, pos := InStr(lf . haystack, lf . needle)
		, InStr(haystack . lf, lf, false, pos) - pos
	If text !=
	{
		ControlSetText, , %text%, ahk_id %h%
		ControlSend, , % "{Right " . StrLen(needle) . "}+^{End}", ahk_id %h%
	}
}

GuiClose:
ExitApp

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


  • Guests
  • Last active:
  • Joined: --
reg. Titans last snippet.

When i type anything thats not added for autocomp all words is inserted ..is it something on my machine that cause this? How can escape from autocomp if no matches after a letter.

I intend to use it with Runbox

Jero3n
  • Members
  • 147 posts
  • Last active: Mar 31 2010 05:07 PM
  • Joined: 19 Jan 2007
I have that problem also, when it doens't match anything it adds the whole list :S
Is there a way to fix this?

daorc
  • Members
  • 177 posts
  • Last active:
  • Joined: 18 Oct 2006
Added "if pos != 0"

Gui, Add, ComboBox, vSel w120 r5 gAC, |0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111 
Gui, Show, , Example 
Return 

AC: 
AutoComplete(A_GuiControl) 
Return 

AutoComplete(ctrl) { 
   static lf = "`n" 
   If GetKeyState("Delete") or GetKeyState("Backspace") 
      Return 
   SetControlDelay, -1 
   SetWinDelay, -1 
   GuiControlGet, h, Hwnd, %ctrl% 
   ControlGet, haystack, List, , , ahk_id %h% 
   GuiControlGet, needle, , %ctrl% 
   StringMid, text, haystack, pos := InStr(lf . haystack, lf . needle) 
      , InStr(haystack . lf, lf, false, pos) - pos 
   If text !=
   {
      if pos != 0
      { 
         ControlSetText, , %text%, ahk_id %h% 
         ControlSend, , % "{Right " . StrLen(needle) . "}+^{End}", ahk_id %h% 
      } 
   }
} 

GuiClose: 
ExitApp

Daorc :)

daorc
  • Members
  • 177 posts
  • Last active:
  • Joined: 18 Oct 2006
is anyone else having trouble with a sticky shift key after typing into this box (ie shift is down when not pressed)? or any ideas thow to avoid this? (appart from the hacky getkeystate + setkeystate)