AutoHotkey Community

It is currently May 25th, 2012, 10:23 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: February 25th, 2005, 8:44 pm 
Offline

Joined: January 1st, 2005, 11:54 am
Posts: 75
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 February 27th, 2005, 10:09 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2005, 9:16 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I've a feeling this will be useful. Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2005, 8:52 pm 
Offline

Joined: October 9th, 2004, 8:55 pm
Posts: 217
Location: Budapest, Hungary
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2005, 8:55 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
nice script! and a good addition to my scriptlet library! :)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2005, 3:06 pm 
Offline

Joined: January 1st, 2005, 11:54 am
Posts: 75
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2006, 7:26 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2006, 12:00 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2006, 1:39 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 17th, 2006, 12:23 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2006, 6:18 am 
Offline

Joined: May 19th, 2006, 4:56 am
Posts: 166
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2006, 10:09 am 
ReallyUltraFast 320mph, sorry 3200mph Wink
10x-1000x more fast

http://www.autohotkey.com/forum/topic30 ... h&start=75


Report this post
Top
  
Reply with quote  
PostPosted: June 6th, 2006, 10:33 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2006, 5:15 pm 
Offline

Joined: November 17th, 2005, 10:14 pm
Posts: 196
Location: Leicester, UK
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. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 9th, 2006, 7:41 pm 
Offline

Joined: January 1st, 2005, 11:54 am
Posts: 75
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.

Image

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 15th, 2006, 7:11 am 
Code:
settitlematchmode 3
is highly recommended in the useful script Kollektor


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: ELengefeld, IsNull, tidbit, toddintr and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group