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
; --------------------------------------------------------------------- ; 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