Jump to content
Sign in to follow this  
monsterkodi

GUI: List/Tree-View item selection by word typing

Recommended Posts

monsterkodi

Hello,

if a ListView or TreeView has the keyboard focus and i start typing, the item that starts with the typed letters gets selected.

A new search is started when there is no keyboard input for approximately 1-2 seconds.

I would like to know if it is possible to set the duration of this delay somehow.

I would also like to know if there is a way to receive the pressed keys. The documentation states that these Controls swallow the

WM_KEYDOWN messages. Is there no way to receive them in my script nevertheless?

Thanks in advance for any answer,

yours kodi

Share this post


Link to post
Share on other sites
Melba23

monsterkodi,

First, welcome to the AutoIt forums. :)

Here is a first second cut at what you wanted. The only thing I cannot resolve is that the first item is always selected when you start - seems like a default setting and I have seen it remarked upon elsewhere in these forums. ;)

#include <GUIConstantsEx.au3>
#include <ListviewConstants.au3>
#Include <GuiListView.au3>
#include <String.au3>

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

; Create LV
$hListView = GUICtrlCreateListView("                      ", 10, 10, 200, 220)
GUICtrlSetBkColor(-1, 0x0AFFB0)

; Fill LV
For $i = 0 To 9
    GUICtrlCreateListViewItem(_StringRepeat(Chr(65 + $i), 7), $hListView)
Next

; Create Input
$hInput = GUICtrlCreateInput("", 250, 10, 200, 20)

GUISetState()

; Set up LV search structure
$tInfo = DllStructCreate($tagLVFINDINFO)
DllStructSetData($tInfo, "Flags", $LVFI_PARTIAL) ; Looking for partial matches

; Set intitial values
$iOld_Index = -1
$sCurr_Input = GUICtrlRead($hInput)
$iBegin = TimerInit()

While 1

    ; Look for [X} click
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Reset Input if no change in 2 secs
    ; Wait until 2 secs have passed
    If TimerDiff($iBegin) > 2000 Then
        ; If no change to Input value
        If GUICtrlRead($hInput) = $sCurr_Input Then
            ; Reset Input
            GUICtrlSetData($hInput, "")
            ; Clear all selection in LV
            _GUICtrlListView_SetItemSelected($hListView, -1, False)
        Else
            ; If value has changed, store current input and reset timer
            $sCurr_Input = GUICtrlRead($hInput)
            $iBegin = TimerInit()
        EndIf
    EndIf

    ; Search the LV for element containing Inpit content
    $iIndex = _GUICtrlListView_FindItem($hListView, -1, $tInfo, GUICtrlRead($hInput))
    ; If the selection has changed
    If $iIndex <> $iOld_Index Then
        ; Clear old selection in LV and set new one
        _GUICtrlListView_SetItemSelected($hListView, -1, False)
        _GUICtrlListView_SetItemSelected($hListView, $iIndex)
        ; Store current selection
        $iOld_Index = $iIndex
    EndIf
WEnd

As to receiving the pressed keys, I am unsure what exactly you mean. You can read what is in the Input by using GUICtrlRead, as you can see in the script. Is that enough? I should warn you that keyloggers (saving every key pressed) are very much NOT welcome here because of the obvious possibilites of malicious use.

M23

Edit: Updated and improved script example removing some earlier problems.

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
monsterkodi

Hello M23,

thanks for your welcome and your script.

Unfortunately, it isn't quite what I expected.

I don't really want to re-implement the tree view navigation.

I would like to leave the focus in the tree view and just change the delay after which the search string gets resetted.

While browsing the MSDN, i found a solution to my second question: sending a TVM_GETISEARCHSTRING message will retrieve the search string.

But that also tells me that the incremental search is done in a part controlled by Microsoft, not by AutoIt, and therefore probably not tweakable without the corresponding interface.

After all, maybe I have to do it your way in the end.

Thanks again for your help and a general sorry to everybody for starting this thread in the wrong section (just discovered the UI topic :) )

yours kodi

Share this post


Link to post
Share on other sites
Melba23

monsterkodi,

your script. Unfortunately, it isn't quite what I expected

Just to make sure you realise that normally we expect you to make an effort at coding something yourself first before we chip in with suggestions. I was being extra nice to welcome you to the forums - as Sir Percy said to Courtney "Do not expect treats like this every day"! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
monsterkodi

Hello M23,

I sense some misunderstanding here. I really appreciate your help.

You provided a workaround for my problem because it probably can't be solved directly, which is very nice of you.

I don't expect treats like this every day, please forgive me my bad wording.

Peace,

yours kodi

Share this post


Link to post
Share on other sites
Melba23

monsterkodi,

Peace to you too. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.