 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Boskoop
Joined: 01 Jan 2005 Posts: 73
|
Posted: Fri Feb 25, 2005 8:44 pm Post subject: Listbox with incremental search |
|
|
This script makes a listbox which can be searched incrementally.
The choosen item is assigned to a variable for further processing.
I needed it as part of a larger script.
I used Keyboardfreak's script "iswitchw - Incrementally switch
between windows using substrings" as a template. Nearly all the code comes
from that script. Only the errors er mine. Thanx Keyboardfreak!
Knowing nearly nothing about programming, it took me quite a long time
to extract the code I needed from Keyboardfreaks script (11 pages, printed!).
So I decided to post it in case others have the same problem and may find it useful.
Boskoop
| Code: |
; ---------------------------------------------------------------------
; Name: Incremental Listbox
; Date: 25.2.2005
; Autor: Boskoop
; Language: english
; Platform: tested with XP
; AHK-Version: 1.24
;
; Description:
; ---------------------------------------------------------------------
; On pressing CapsLock, the script
; shows a listbox. The listbox retrieves its contents from a text-file.
; It's possible do to an incremental search in this listbox:
; The listbox shows only the items starting with the letter(s) you type.
;
; Most of the code is from the script "iswitchw - Incrementally switch
; between windows using substrings" by Keyboardfreak. Thanks.
; All errors er mine.
; ---------------------------------------------------------------------
; ---------------------------------------------------------------------
; -- Configuration: ---------------------------------------------------
; ---------------------------------------------------------------------
;Your favourite hotkey:
CapsLock:: ;Hotkey CapsLock to start
;The name of the textfile containing the contents of the listbox:
ListName=Boskoop_Testfile_.tmp
; ---------------------------------------------------------------------
; -- Initialize: -------------------------------------------------
; ---------------------------------------------------------------------
;The following part is just for getting a working script. It should be removed
;when using the script as part of another script.
;This produces a file, named Boskoop_Testfile_.tmp and places in the working directory.
;Delete this file after playing with this script.
;The file contains a wordlist,which is used to fill the listbox.
IfInString,Listname,Boskoop_Testfile_
{
Fileappend, car`nbicyle`ntrain`nplane`nroad`nrailway station`ntrack`nairport`ncontrol tower`nwheel`nred`ngreen`npink`nblue`ngrey
`nsilver`nblack`nyellow`nbrown`nwhite`nhair`nnose`neye`near`nface`nmustache`nneck`ncollar`narm`nhand`nforearm`nforehead
`nfinger`nthumb`npalm`nback`nstomach`nleg`nthigh`nfoot`ntoe`nshoe`nsock`nstocking`ntrousers`njumpsuit`nskirt`nblouse`ndress`nshirt
`ntie`nnecklace`nearring`nSun`nMoon`nMercur`nVenus`nEarth`nMars`nJupiter`nSaturn`nNeptun`nPluto
`nAfrica`nAmerica`nAntarctica`nAsia`nAustralia`nEurope`nCanada`nUSA`nMexico`nGuatemala`nHonduras`nCuba`n,%ListName%
}
; ---------------------------------------------------------------------
; -- Autoexecute ------------------------------------------------------
; ---------------------------------------------------------------------
Gui, Add, ListBox, vChoice gListBoxClick w300 h250 hscroll vscroll
Gui, Add, Text, x6 y264 w50 h20, Search`:
Gui, Add, Edit, x66 y261 w240 h20
Gosub RefreshListBox
search =
;The input-command in this loop processes keys pressed by the user
;or send by the "send"-command
Loop
{
Input, input, L1, {enter}{esc}{backspace}{up}{down}{pgup}{pgdn}{tab}{left}{right}
if ErrorLevel = EndKey:escape
{
Gui, cancel
Gosub GuiClose
}
if ErrorLevel = EndKey:enter
{
GoSub, WordRetrieve
continue
}
if ErrorLevel = EndKey:backspace
{
GoSub, DeleteSearchChar
continue
}
if ErrorLevel = EndKey:up
{
Send, {up}
continue
}
if ErrorLevel = EndKey:down
{
Send, {down}
continue
}
if ErrorLevel = EndKey:pgup
{
Send, {pgup}
continue
}
if ErrorLevel = EndKey:pgdn
{
Send, {pgdn}
continue
}
search = %search%%input% ;Assembles the search string
GuiControl,, Edit1, %search% ;Displays the search string in the edit control
StringLen,SearchLength,Search
Gosub RefreshListBox
continue
}
return
; ---------------------------------------------------------------------
; -- Subroutines ------------------------------------------------------
; ---------------------------------------------------------------------
;Assigns the chosen item to the variable "Choice".
WordRetrieve:
Gui, submit, noHide
GuiControlGet, Choice ; Retrieve the ListBox's current selection.
msgBox, You choose:`n`n%Choice%
return
; ---------------------------------------------------------------------
;Exits the script on closing the GUI
GuiClose:
GuiEscape:
ExitApp
; ---------------------------------------------------------------------
;Refreshes the listbox according to the search criteria:
RefreshListBox:
Wordlist=
Loop, read, %ListName%
{
StringLeft, Fragment,A_LoopReadLine, %SearchLength%
IfInString, Fragment,%Search%
Wordlist=%Wordlist% |%A_LoopReadLine%
Else
continue
}
Gui, Show,
GuiControl,, ListBox1, %wordlist%
GuiControl, Choose, ListBox1, 1
return
;-------------------------------------------------------------------------
;Delete the last character and update Listbox:
DeleteSearchChar:
if search =
return
StringTrimRight, search, search, 1
GuiControl,, Edit1, %search%
GoSub, RefreshListBox
return
;-------------------------------------------------------------------------
; Handle mouse click events on the list box:
ListBoxClick:
if A_GuiControlEvent = DoubleClick
send, {enter}
return
|
Last edited by Boskoop on Sun Feb 27, 2005 10:09 pm; edited 1 time in total |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10666
|
Posted: Fri Feb 25, 2005 9:16 pm Post subject: |
|
|
| I've a feeling this will be useful. Thanks. |
|
| Back to top |
|
 |
keyboardfreak
Joined: 09 Oct 2004 Posts: 196 Location: Budapest, Hungary
|
Posted: Sat Feb 26, 2005 8:52 pm Post subject: |
|
|
Good idea. Two comments:
| Quote: | | Input, input, L1, {enter}{esc}{backspace}{up}{down}{pgup}{pgdn}{tab}{left}{right} |
You probably don't need the {tab}{left}{right} keys in the Input command, since you don't handle those cases. They are probably leftovers from my original script.
As you probably know the Input command grabs the keyboard input, so you can't use the keyboard in other applications while this command is running. It is no problem for the window switcher, since you're not likely to use an other application while swicthing between windows.
However, if you plan to make your incremental listbox a part of a more usual application (where it's normal to use other apps while your script is running) then it could be a problem. |
|
| Back to top |
|
 |
Rajat
Joined: 28 Mar 2004 Posts: 1687
|
Posted: Sat Feb 26, 2005 8:55 pm Post subject: |
|
|
nice script! and a good addition to my scriptlet library!  _________________
 |
|
| Back to top |
|
 |
Boskoop
Joined: 01 Jan 2005 Posts: 73
|
Posted: Sun Feb 27, 2005 3:06 pm Post subject: |
|
|
Thanks for your kind feedback. This was actually the first time I did post anything else but stupid questions.
@keyboardfreak: Your "iswitchw"-script i a treasury full of useful subroutines. Thanks again for it.
I noticed that "input" grabs all the keyboard input. It's no problem for my script (a keyword-tool, which sends the chosen item to a given control). But you are right- it may pose a problem in other applications.
I'm not sure, maybe it's possible to use an edit control instead of "input".
Another issue is that this gets really slow when using long lists. Its unusable for one of my lists with>20.000 keywords . I have no idea how to resolve this (except for buying a faster computer...).
Boskoop |
|
| Back to top |
|
 |
ratz Guest
|
Posted: Wed Mar 15, 2006 7:26 pm Post subject: |
|
|
Great script! Question: How can i make this work with multiple words. I noticed that when i type a {space}, the character isnt shown in the listbox. Is this necessary to make tbe script work?
for example, if i put in the boskoop.tmp file, "railway station" and "railway stationary," the script wont let me go to the second word. Or if i put "railway student," there is no way of choosing this.
Is there anyway of making this work? Thanks. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6786 Location: France (near Paris)
|
Posted: Thu Mar 16, 2006 12:00 pm Post subject: |
|
|
Good idea, but the code is a bit outdated, no need for Input now: the Edit control can fire an event on each typed key.
Here is my take at this kind of script:
| Code: | Gui Add, Edit, w300 h20 vsearchedString gIncrementalSearch
Gui Add, ListBox, vchoice gListBoxClick w300 h250 hscroll vscroll
Gui Add, Button, gListBoxClick Default, OK
Gosub FillListBox
Gui Show
Return
IncrementalSearch:
Gui Submit, NoHide
len := StrLen(searchedString)
itemNb := 1
Loop Parse, listContent, |
{
StringLeft part, A_LoopField, len
;~ Tooltip %part% (%A_LoopField%)
;~ Sleep 500
If (part = searchedString)
{
itemNb := A_Index
Break
}
}
Tooltip %searchedString% (%itemNb%)
SetTimer HideTooltip, 1000
GuiControl Choose, choice, %itemNb%
Return
HideTooltip:
SetTimer HideTooltip, Off
Tooltip
Return
ListBoxClick:
Gui Submit, NoHide
MsgBox Choice: %choice%
Return
GuiClose:
GuiEscape:
ExitApp
FillListBox:
listContent =
( Join|
car|bicyle|train|plane|road|railway station|track|airport|control tower|wheel
red|green|pink|blue|grey|silver|black|yellow|brown|white
hair|nose|eye|ear|face|mustache|neck|collar|arm|hand|forearm|forehead
finger|thumb|palm|back|stomach|leg|thigh|foot|toe
shoe|sock|stocking|trousers|jumpsuit|skirt|blouse|dress|shirt|tie|necklace|earring
Sun|Moon|Mercure|Venus|Earth|Mars|Jupiter|Saturn|Neptun|Pluto
Africa|America|Antarctica|Asia|Australia|Europe
Canada|USA|Mexico|Guatemala|Honduras|Cuba
Gui Add|Gui Show|Gui Submit|Gui Hide|Gui Destroy
)
GuiControl, , choice, %listContent%
Return
|
Seems to work OK with Space.
If I missed some functionnality, perhaps I can add it. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
ratz Guest
|
Posted: Sat Mar 18, 2006 1:39 am Post subject: |
|
|
Wow PhiLho! Perfect. Exactly what I was looking for. Works great, and much cleaner.
For the "FillListBox" routine, I can read these from a text file right? Ill try...
Thank you very much. Greatly appreciative. |
|
| Back to top |
|
 |
fast Guest
|
Posted: Wed May 17, 2006 12:23 pm Post subject: |
|
|
great script!
Is there any way to make one script for read a txt file with a list of word eg:
able
about
above
across
act
action
actually
add
added
adding
and when I type "dd" see in the edit all the word content "dd" (in this case, add added adding,
like an "autocomplete" but in all position of the caracters) with istant refresh?
TNX |
|
| Back to top |
|
 |
scriptmonkey
Joined: 19 May 2006 Posts: 140
|
Posted: Fri May 19, 2006 6:18 am Post subject: |
|
|
Anyone know if someone made a script like this :
I have about 16,000 PDF files with unique filenames in a folder, but some of them revisions. Examples: 1234.pdf, 1234_00.pdf, 1234_01.pdf, etc. I would like the user to be able to type a filename they are looking for, and the script searches for all files with that #. So if the user types 1234, all files thta start with 1234 will show up in the search. The user would then be able to double-click any of the filenames to open the PDF. |
|
| Back to top |
|
 |
fast Guest
|
|
| Back to top |
|
 |
Guest
|
Posted: Tue Jun 06, 2006 10:33 am Post subject: Listbox incremental search - RESTART LISTBOX AUTOMATICALLY |
|
|
I've adapted the subroutine WordRetrieve to send the item of the list (see )
;Assigns the chosen item to the variable "Choice".
WordRetrieve:
Gui, submit, noHide
GuiControlGet, Choice ; Retrieve the ListBox's current selection.
Gui, Hide
Send, %Choice% ; adaption
ExitApp
return
I have ot insert many items one after another. How do I restart the listbox automatically without hotkey?
Thanks in advance
Dirk |
|
| Back to top |
|
 |
MsgBox
Joined: 17 Nov 2005 Posts: 176 Location: Leicester, UK
|
Posted: Thu Jun 08, 2006 5:15 pm Post subject: |
|
|
Here is a similar script of Laszlo's that I've found to be very useful.
Incremental search for text to send
I made a list of all AHK commands and added it to List=
| Code: | List =
#AllowSameLineComments|#ClipboardTimeout|#CommentFlag etc |
Result = no more misspelt commands.  |
|
| Back to top |
|
 |
Boskoop
Joined: 01 Jan 2005 Posts: 73
|
Posted: Fri Jun 09, 2006 7:41 pm Post subject: |
|
|
The script that used "Listbox with incremental search" made some progress since february 05. Unfortunately I got stuck in the middle of the english translation (no time because of nice weather, work, and a lot of other projects) so I posted it in the German forum.
Kollektor is a crossbreed between clipboard tool and text module tool. You can add highlighted text to the phrase list by pressing CTRL-Capslock. Pressing Capslock shows a list of phrases. You can filter it by typing part of a word. By pressing "Enter" the phrase is inserted in the last active text-window.
There seems to be some interest in the functionality- so maybe someone finds this useful. You can download it here. Both the script's comments and the helpfile are in German. But I'm working on it...
Boskoop |
|
| Back to top |
|
 |
robiandi Guest
|
Posted: Thu Jun 15, 2006 7:11 am Post subject: |
|
|
| Code: | | settitlematchmode 3 | is highly recommended in the useful script Kollektor |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|