Jump to content

Autocomplete by filtering the results - (Moved)


Recommended Posts

Dear friends of the forum, I've been trying to do an autocompletion filtering the results for days, disabling the characters that are not part of the result, but without success. Some friends could give me a start, the gif image shows what I'm trying to do, any start would help me. thanks.

 

AN0HtPxu_o.gif

Link to post
Share on other sites
  • Developers

Moved to the appropriate AutoIt General Help and Support forum, as the AutoIt Example Scripts forum very clearly states:

Quote

Share your cool AutoIt scripts, UDFs and applications with others.


Do not post general support questions here, instead use the AutoIt Help and Support forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

Keyboard layout.

Spoiler
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>

Opt("MustDeclareVars", 1)

Local $btnBG = 0x6699FF
Global $BTN[41]
Global $BTN_L[41] = ["", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", _
                        "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", _
                        "A", "S", "D", "F", "G", "H", "J", "K", "L", "Ç", _
                        "Z", "X", "C", "V", "B", "N", "M", "DEL", "OK", _
                        "SPACE"]
Local $posX = 3
Local $posY = 115
Local $btnSZw = 98
Local $btnSZh = 98


Local $GUI = GUICreate("keyboard", 1024, 637, -1, -1, $WS_POPUP)
GUISetBkColor(0x000000)
Local $chrBox = GUICtrlCreateLabel("", 20, 22, 984, 68, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0xEBEBEB)
GUICtrlSetFont(-1, 38, 700, 0, "Arial", 5)

For $ii = 1 To 40
    Switch $ii
        Case 11
            $btnBG = 0xCCCCCC
            $posX = 3
            $posY = 217
        Case 21
            $posX = 3
            $posY = 319
        Case 31
            $posX = 43
            $posY = 421
        Case 38
            $btnBG = 0xFF3333
            $posX = 794
            $posY = 421
        Case 39
            $btnBG = 0x00FF00
            $posX = 896
            $posY = 421
        Case 40
            $btnBG = 0xFFFFFF
            $btnSZw = 400
            $posX = 313
            $posY = 524
    EndSwitch

    $BTN[$ii] = GUICtrlCreateLabel($BTN_L[$ii], $posX, $posY, $btnSZw, $btnSZh, BitOR($SS_CENTER, $SS_CENTERIMAGE))
    GUICtrlSetBkColor(-1, $btnBG)
    GUICtrlSetFont(-1, 38, 700, 0, "Arial", 5)

    $posX += 102
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

 

 

Link to post
Share on other sites

Hi @mutleey,

looks promising, but I guess it's still a long way 😅 . How do you plan to disable each key? One by one like this:

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $BTN[1]
            GUICtrlSetBkColor($BTN[1], 0xD1E0FF)
        Case $BTN[2]
            GUICtrlSetBkColor($BTN[2], 0xD1E0FF)
    EndSwitch
WEnd

Wouldn't be pretty handy I guess. Any specific questions? Out of your first post I can't see a concrete issue or something.

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔍 Forum search

🔮 Me on GitHub

💬 Opinion about new forum sub category

 📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to post
Share on other sites

The idea is to do as this script does, but disabling the keys that are not part of the result.

Spoiler
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#Include <GuiListBox.au3>
#include <WindowsConstants.au3>
#include <File.au3>

;~ Global $asKeyWords[21] = [20, "fight", "first", "fly", "third", "fire", "wall", "hi", "hello", "world", "window", _
;~         "window 1", "window 2", "window 3", "window 4", "window 5", "window 6", "window 7", "window 8", "window 9", "window 10"]
Global $asKeyWords = _FileListToArrayRecEx("C:\Windows\System32", "*.exe", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_NOPATH)
;~ _ArrayDisplay($asKeyWords)


Local $hGUI, $hList, $hInput, $aSelected, $sChosen, $hUP, $hDOWN, $hENTER, $hESC
Local $sCurrInput = "", $aCurrSelected[2] = [-1, -1], $iCurrIndex = -1, $hListGUI = -1

$hGUI = GUICreate("AutoComplete Input Text", 300, 100)
GUICtrlCreateLabel('Start to type words like "window" or "fire" to test it:', 10, 10, 280, 20)
$hInput = GUICtrlCreateInput("", 10, 40, 280, 20)
GUISetState(@SW_SHOW, $hGUI)

$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
$hESC = GUICtrlCreateDummy()
Dim $AccelKeys[4][2] = [["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER], ["{ESC}", $hESC]]
GUISetAccelerators($AccelKeys)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $hESC
            If $hListGUI <> -1 Then ; List is visible.
                GUIDelete($hListGUI)
                $hListGUI = -1
            Else
                ExitLoop
            EndIf

        Case $hUP
            If $hListGUI <> -1 Then ; List is visible.
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then
                    $iCurrIndex = 0
                EndIf
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf

        Case $hDOWN
            If $hListGUI <> -1 Then ; List is visible.
                $iCurrIndex += 1
                If $iCurrIndex > _GUICtrlListBox_GetCount($hList) - 1 Then
                    $iCurrIndex = _GUICtrlListBox_GetCount($hList) - 1
                EndIf
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf

        Case $hENTER
            If $hListGUI <> -1 And $iCurrIndex <> -1 Then ; List is visible and a item is selected.
                $sChosen = _GUICtrlListBox_GetText($hList, $iCurrIndex)
            EndIf

        Case $hList
            $sChosen = GUICtrlRead($hList)
    EndSwitch

;~  Sleep(10)
    $aSelected = _GetSelectionPointers($hInput)
    If GUICtrlRead($hInput) <> $sCurrInput Or $aSelected[1] <> $aCurrSelected[1] Then ; Input content or pointer are changed.
        $sCurrInput = GUICtrlRead($hInput)
        $aCurrSelected = $aSelected ; Get pointers of the string to replace.
        $iCurrIndex = -1
        If $hListGUI <> -1 Then ; List is visible.
            GUIDelete($hListGUI)
            $hListGUI = -1
        EndIf
        $hList = _PopupSelector($hGUI, $hListGUI, _CheckInputText($sCurrInput, $aCurrSelected)) ; ByRef $hListGUI, $aCurrSelected.
    EndIf

    If $sChosen <> "" Then
        GUICtrlSendMsg($hInput, 0x00B1, $aCurrSelected[0], $aCurrSelected[1]) ; $EM_SETSEL.
        _InsertText($hInput, $sChosen)
        $sCurrInput = GUICtrlRead($hInput)
        GUIDelete($hListGUI)
        $hListGUI = -1
        $sChosen = ""
    EndIf
WEnd

GUIDelete($hGUI)



Func _CheckInputText($sCurrInput, ByRef $aSelected)
    Local $sPartialData = ""
    If (IsArray($aSelected)) And ($aSelected[0] <= $aSelected[1]) Then
        Local $aSplit = StringSplit(StringLeft($sCurrInput, $aSelected[0]), " ")
        $aSelected[0] -= StringLen($aSplit[$aSplit[0]])
        If $aSplit[$aSplit[0]] <> "" Then
            For $A = 1 To $asKeyWords[0]
                If StringLeft($asKeyWords[$A], StringLen($aSplit[$aSplit[0]])) = $aSplit[$aSplit[0]] And $asKeyWords[$A] <> $aSplit[$aSplit[0]] Then
                    $sPartialData &= $asKeyWords[$A] & "|"
                EndIf
            Next
        EndIf
    EndIf
    Return $sPartialData
EndFunc   ;==>_CheckInputText



Func _PopupSelector($hMainGUI, ByRef $hListGUI, $sCurr_List)
    Local $hList = -1
    If $sCurr_List = "" Then
        Return $hList
    EndIf
    $hListGUI = GUICreate("", 280, 160, 10, 62, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_MDICHILD), $hMainGUI)
    $hList = GUICtrlCreateList("", 0, 0, 280, 150, BitOR(0x00100000, 0x00200000))
    GUICtrlSetData($hList, $sCurr_List)
    GUISetControlsVisible($hListGUI) ; To Make Control Visible And Window Invisible.
    GUISetState(@SW_SHOWNOACTIVATE, $hListGUI)
    Return $hList
EndFunc   ;==>_PopupSelector



Func _InsertText(ByRef $hEdit, $sString)
    #cs
        Description: Insert A Text In A Control.
        Returns: Nothing
    #ce
    Local $aSelected = _GetSelectionPointers($hEdit)
    GUICtrlSetData($hEdit, StringLeft(GUICtrlRead($hEdit), $aSelected[0]) & $sString & StringTrimLeft(GUICtrlRead($hEdit), $aSelected[1]))
    Local $iCursorPlace = StringLen(StringLeft(GUICtrlRead($hEdit), $aSelected[0]) & $sString)
    GUICtrlSendMsg($hEdit, 0x00B1, $iCursorPlace, $iCursorPlace) ; $EM_SETSEL.
EndFunc   ;==>_InsertText



Func _GetSelectionPointers($hEdit)
    Local $aReturn[2] = [0, 0]
    Local $aSelected = GUICtrlRecvMsg($hEdit, 0x00B0) ; $EM_GETSEL.
    If IsArray($aSelected) Then
        $aReturn[0] = $aSelected[0]
        $aReturn[1] = $aSelected[1]
    EndIf
    Return $aReturn
EndFunc   ;==>_GetSelectionPointers



Func GUISetControlsVisible($hWnd) ; By Melba23.
    Local $aControlGetPos = 0, $hCreateRect = 0, $hRectRgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    Local $iLastControlID = _WinAPI_GetDlgCtrlID(GUICtrlGetHandle(-1))
    For $i = 3 To $iLastControlID
        $aControlGetPos = ControlGetPos($hWnd, '', $i)
        If IsArray($aControlGetPos) = 0 Then ContinueLoop
        $hCreateRect = _WinAPI_CreateRectRgn($aControlGetPos[0], $aControlGetPos[1], $aControlGetPos[0] + $aControlGetPos[2], $aControlGetPos[1] + $aControlGetPos[3])
        _WinAPI_CombineRgn($hRectRgn, $hCreateRect, $hRectRgn, 2)
        _WinAPI_DeleteObject($hCreateRect)
    Next
    _WinAPI_SetWindowRgn($hWnd, $hRectRgn, True)
    _WinAPI_DeleteObject($hRectRgn)
EndFunc   ;==>GUISetControlsVisible


; #FUNCTION# ====================================================================================================================
; Author ........: Melba23 - with credits for code snippets to Ultima, Partypooper, Spiff59, guinness, wraithdu
; Modified ......:
; ===============================================================================================================================
Func _FileListToArrayRecEx($sFilePath, $sMask = "*", $iReturn = $FLTAR_FILESFOLDERS, $iRecur = $FLTAR_NORECUR, $iSort = $FLTAR_NOSORT, $iReturnPath = $FLTAR_RELPATH)
    If Not FileExists($sFilePath) Then Return SetError(1, 1, "")

    ; Check for Default keyword
    If $sMask = Default Then $sMask = "*"
    If $iReturn = Default Then $iReturn = $FLTAR_FILESFOLDERS
    If $iRecur = Default Then $iRecur = $FLTAR_NORECUR
    If $iSort = Default Then $iSort = $FLTAR_NOSORT
    If $iReturnPath = Default Then $iReturnPath = $FLTAR_RELPATH

    ; Check for valid recur value
    If $iRecur > 1 Or Not IsInt($iRecur) Then Return SetError(1, 6, "")

    Local $bLongPath = False
    ; Check for valid path
    If StringLeft($sFilePath, 4) == "\\?\" Then
        $bLongPath = True
    EndIf

    Local $sFolderSlash = ""
    ; Check if folders should have trailing \ and ensure that initial path does have one
    If StringRight($sFilePath, 1) = "\" Then
        $sFolderSlash = "\"
    Else
        $sFilePath = $sFilePath & "\"
    EndIf

    Local $asFolderSearchList[100] = [1]
    ; Add path to folder search list
    $asFolderSearchList[1] = $sFilePath

    Local $iHide_HS = 0, _
            $sHide_HS = ""
    ; Check for H or S omitted
    If BitAND($iReturn, $FLTAR_NOHIDDEN) Then
        $iHide_HS += 2
        $sHide_HS &= "H"
        $iReturn -= $FLTAR_NOHIDDEN
    EndIf
    If BitAND($iReturn, $FLTAR_NOSYSTEM) Then
        $iHide_HS += 4
        $sHide_HS &= "S"
        $iReturn -= $FLTAR_NOSYSTEM
    EndIf

    Local $iHide_Link = 0
    ; Check for link/junction omitted
    If BitAND($iReturn, $FLTAR_NOLINK) Then
        $iHide_Link = 0x400
        $iReturn -= $FLTAR_NOLINK
    EndIf

    Local $iMaxLevel = 0
    ; If required, determine \ count for max recursive level setting
    If $iRecur < 0 Then
        StringReplace($sFilePath, "\", "", 0, $STR_NOCASESENSEBASIC)
        $iMaxLevel = @extended - $iRecur
    EndIf

    Local $sExclude_List = "", $sExclude_List_Folder = "", $sInclude_List = "*"
    ; Check mask parameter
    Local $aMaskSplit = StringSplit($sMask, "|")
    ; Check for multiple sections and set values
    Switch $aMaskSplit[0]
        Case 3
            $sExclude_List_Folder = $aMaskSplit[3]
            ContinueCase
        Case 2
            $sExclude_List = $aMaskSplit[2]
            ContinueCase
        Case 1
            $sInclude_List = $aMaskSplit[1]
    EndSwitch

    Local $sInclude_File_Mask = ".+"
    ; Create Include mask for files
    If $sInclude_List <> "*" Then
        If Not __FLTAR_ListToMask($sInclude_File_Mask, $sInclude_List) Then Return SetError(1, 2, "")
    EndIf

    Local $sInclude_Folder_Mask = ".+"
    ; Set Include mask for folders
    Switch $iReturn
        Case 0
            ; Folders affected by mask if not recursive
            Switch $iRecur
                Case 0
                    ; Folders match mask for compatibility
                    $sInclude_Folder_Mask = $sInclude_File_Mask
            EndSwitch
        Case 2
            ; Folders affected by mask
            $sInclude_Folder_Mask = $sInclude_File_Mask
    EndSwitch

    Local $sExclude_File_Mask = ":"
    ; Create Exclude List mask for files
    If $sExclude_List <> "" Then
        If Not __FLTAR_ListToMask($sExclude_File_Mask, $sExclude_List) Then Return SetError(1, 3, "")
    EndIf

    Local $sExclude_Folder_Mask = ":"
    ; Create Exclude mask for folders
    If $iRecur Then
        If $sExclude_List_Folder Then
            If Not __FLTAR_ListToMask($sExclude_Folder_Mask, $sExclude_List_Folder) Then Return SetError(1, 4, "")
        EndIf
        ; If folders only
        If $iReturn = 2 Then
            ; Folders affected by normal mask
            $sExclude_Folder_Mask = $sExclude_File_Mask
        EndIf
    Else
        ; Folders affected by normal mask
        $sExclude_Folder_Mask = $sExclude_File_Mask
    EndIf

    ; Verify other parameters
    If Not ($iReturn = 0 Or $iReturn = 1 Or $iReturn = 2) Then Return SetError(1, 5, "")
    If Not ($iSort = 0 Or $iSort = 1 Or $iSort = 2) Then Return SetError(1, 7, "")
    If Not ($iReturnPath = 0 Or $iReturnPath = 1 Or $iReturnPath = 2) Then Return SetError(1, 8, "")

    ; Prepare for DllCall if required
    If $iHide_Link Then
        Local $tFile_Data = DllStructCreate("struct;align 4;dword FileAttributes;uint64 CreationTime;uint64 LastAccessTime;uint64 LastWriteTime;" & _
                "dword FileSizeHigh;dword FileSizeLow;dword Reserved0;dword Reserved1;wchar FileName[260];wchar AlternateFileName[14];endstruct")
        Local $hDLL = DllOpen('kernel32.dll'), $aDLL_Ret
    EndIf

    Local $asReturnList[100] = [0]
    Local $asFileMatchList = $asReturnList, $asRootFileMatchList = $asReturnList, $asFolderMatchList = $asReturnList
    Local $bFolder = False, _
            $hSearch = 0, _
            $sCurrentPath = "", $sName = "", $sRetPath = ""
    Local $iAttribs = 0, _
            $sAttribs = ''
    Local $asFolderFileSectionList[100][2] = [[0, 0]]
    ; Search within listed folders
    While $asFolderSearchList[0] > 0

        ; Set path to search
        $sCurrentPath = $asFolderSearchList[$asFolderSearchList[0]]
        ; Reduce folder search list count
        $asFolderSearchList[0] -= 1
        ; Determine return path to add to file/folder name
        Switch $iReturnPath
            ; Case 0 ; Name only
            ; Leave as ""
            Case 1 ;Relative to initial path
                $sRetPath = StringReplace($sCurrentPath, $sFilePath, "")
            Case 2 ; Full path
                If $bLongPath Then
                    $sRetPath = StringTrimLeft($sCurrentPath, 4)
                Else
                    $sRetPath = $sCurrentPath
                EndIf
        EndSwitch

        ; Get search handle - use code matched to required listing
        If $iHide_Link Then
            ; Use DLL code
            $aDLL_Ret = DllCall($hDLL, 'handle', 'FindFirstFileW', 'wstr', $sCurrentPath & "*", 'struct*', $tFile_Data)
            If @error Or Not $aDLL_Ret[0] Then
                ContinueLoop
            EndIf
            $hSearch = $aDLL_Ret[0]
        Else
            ; Use native code
            $hSearch = FileFindFirstFile($sCurrentPath & "*")
            ; If folder empty move to next in list
            If $hSearch = -1 Then
                ContinueLoop
            EndIf
        EndIf

        ; If sorting files and folders with paths then store folder name and position of associated files in list
        If $iReturn = 0 And $iSort And $iReturnPath Then
            __FLTAR_AddToList($asFolderFileSectionList, $sRetPath, $asFileMatchList[0] + 1)
        EndIf
        $sAttribs = ''

        ; Search folder - use code matched to required listing
        While 1
            ; Use DLL code
            If $iHide_Link Then
                ; Use DLL code
                $aDLL_Ret = DllCall($hDLL, 'int', 'FindNextFileW', 'handle', $hSearch, 'struct*', $tFile_Data)
                ; Check for end of folder
                If @error Or Not $aDLL_Ret[0] Then
                    ExitLoop
                EndIf
                ; Extract data
                $sName = DllStructGetData($tFile_Data, "FileName")
                ; Check for .. or . filename and skip
                If $sName = ".." Or $sName = "." Then
                    ContinueLoop
                EndIf
                $iAttribs = DllStructGetData($tFile_Data, "FileAttributes")
                ; Check for hidden/system attributes and skip if found
                If $iHide_HS And BitAND($iAttribs, $iHide_HS) Then
                    ContinueLoop
                EndIf
                ; Check for link attribute and skip if found
                If BitAND($iAttribs, $iHide_Link) Then
                    ContinueLoop
                EndIf
                ; Set subfolder flag
                $bFolder = False
                If BitAND($iAttribs, 16) Then
                    $bFolder = True
                EndIf
            Else
                ; Reset folder flag
                $bFolder = False
                ; Use native code
                $sName = FileFindNextFile($hSearch, 1)
                ; Check for end of folder
                If @error Then
                    ExitLoop
                EndIf
                ; Check for .. or . filename and skip
                If $sName = ".." Or $sName = "." Then
                    ContinueLoop
                EndIf
                $sAttribs = @extended
                ; Check for folder
                If StringInStr($sAttribs, "D") Then
                    $bFolder = True
                EndIf
                ; Check for Hidden/System
                If StringRegExp($sAttribs, "[" & $sHide_HS & "]") Then
                    ContinueLoop
                EndIf
            EndIf

            ; If folder then check whether to add to search list
            If $bFolder Then
                Select
                    Case $iRecur < 0 ; Check recur depth
                        StringReplace($sCurrentPath, "\", "", 0, $STR_NOCASESENSEBASIC)
                        If @extended < $iMaxLevel Then
                            ContinueCase ; Check if matched to masks
                        EndIf
                    Case $iRecur = 1 ; Full recur
                        If Not StringRegExp($sName, $sExclude_Folder_Mask) Then ; Add folder unless excluded
                            __FLTAR_AddToList($asFolderSearchList, $sCurrentPath & $sName & "\")
                        EndIf
                        ; Case $iRecur = 0 ; Never add
                        ; Do nothing
                EndSelect
            EndIf

            If $iSort Then ; Save in relevant folders for later sorting
                If $bFolder Then
                    If StringRegExp($sName, $sInclude_Folder_Mask) And Not StringRegExp($sName, $sExclude_Folder_Mask) Then
                        __FLTAR_AddToList($asFolderMatchList, $sRetPath & $sName & $sFolderSlash)
                    EndIf
                Else
                    If StringRegExp($sName, $sInclude_File_Mask) And Not StringRegExp($sName, $sExclude_File_Mask) Then
                        ; Select required list for files
                        If $sCurrentPath = $sFilePath Then
                            __FLTAR_AddToList($asRootFileMatchList, $sRetPath & $sName)
                        Else
                            __FLTAR_AddToList($asFileMatchList, $sRetPath & $sName)
                        EndIf
                    EndIf
                EndIf
            Else ; Save directly in return list
                If $bFolder Then
                    If $iReturn <> 1 And StringRegExp($sName, $sInclude_Folder_Mask) And Not StringRegExp($sName, $sExclude_Folder_Mask) Then
                        __FLTAR_AddToList($asReturnList, $sRetPath & $sName & $sFolderSlash)
                    EndIf
                Else
                    If $iReturn <> 2 And StringRegExp($sName, $sInclude_File_Mask) And Not StringRegExp($sName, $sExclude_File_Mask) Then
                        __FLTAR_AddToList($asReturnList, $sRetPath & $sName)
                    EndIf
                EndIf
            EndIf

        WEnd

        ; Close current search
        If $iHide_Link Then
            DllCall($hDLL, 'int', 'FindClose', 'ptr', $hSearch)
        Else
            FileClose($hSearch)
        EndIf

    WEnd

    ; Close the DLL if needed
    If $iHide_Link Then
        DllClose($hDLL)
    EndIf

    Return $asReturnList
EndFunc   ;==>_FileListToArrayRec

 

 

Link to post
Share on other sites

I will later have a deeper look into it.

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔍 Forum search

🔮 Me on GitHub

💬 Opinion about new forum sub category

 📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to post
Share on other sites

Ok, I think I now understand what you want.  You have a list of keyword, and you want the user to enter only valid entry by disabling keys that cannot be part of the words left as the user enters characters in an input field.  Is that it ?

Link to post
Share on other sites
Posted (edited)
38 minutes ago, Nine said:

Ok, I think I now understand what you want.  You have a list of keyword, and you want the user to enter only valid entry by disabling keys that cannot be part of the words left as the user enters characters in an input field.  Is that it ?

Based on the script above, when typing the letter X in the search, all keys with the exception of C, P, W, L (which are the possible options) would be disabled, and so on until one option remains. The gif above shows the example well.

search.jpg

Edited by mutleey
Link to post
Share on other sites

This is an example script on how to filter from an array:

#include <Array.au3>
Dim $tt[0]

$words="test|teaser|teatime|tension|Best|beaser|beatime|bension"
_ArrayAdd($tt,$words,0,"|")

$words=StringReplace(StringReplace($words,"|B",@CRLF & "b",0,1),"|"," ")
While 1
$in=InputBox ("Enter a text to show the available next chars","From these words:" & @CRLF &@CRLF & $words &  @CRLF & @CRLF & "Enter end to stop","","",320)
If $in="end" then Exit

CW(@crlf & "******************" & @crlf & "Input string = " & $in & @CRLF)

for $x=0 to UBound($tt)-1
    if StringMid($tt[$x],1,StringLen($in))=$in Then
        $nl=StringMid($tt[$x],StringLen($in)+1,1)
    CW("Available next letter= '" & $nl & "' from " & $tt[$x],1)
    EndIf
Next

Wend

Func CW($txt,$crlf=1)
    Local $nl=""
    if $crlf=1 then $nl=@CRLF
    ConsoleWrite ($txt & $nl)
EndFunc

it should give you an idea on how to proceed. 
p.s. the last 4 test words are the same as the 1st just with the t swapped with a b, for testing purpose.

Edited by Dan_555

Some of my script sourcecode

Link to post
Share on other sites

Here my take on your request.  Instead of using your keyboard, I have use a hook that disables unauthorized keys.

#include <Constants.au3>
#include <GUIConstants.au3>
#include <WinAPISys.au3>
#include <WinAPIConstants.au3>
#include <WinAPIProc.au3>
#include <Array.au3>

Opt("MustDeclareVars", True)

Global $aKeyWords[] = ["fight", "first", "fly", "third", "fire", "wall", "hi", "high", "hello", "world", "window", _
          "window 1", "window 2", "window 3", "window 4", "window 5", "window 6", "window 7", "window 8", "window 9", "window 10"]
Global $aAllowedChar = EnumerateChar(1, $aKeyWords)
Global $hHook, $idList, $idDummy, $bAllowed

Local $sSelected = SelectWord()
MsgBox($MB_SYSTEMMODAL, "You have selected", $sSelected)

Func SelectWord()
  Local $hGui = GUICreate("Select Word")
  $idList = GUICtrlCreateInput("", 10, 10, 100, 20)
  $idDummy = GUICtrlCreateDummy()
  Local $idKey = GUICtrlCreateDummy()
  Local $hStub = DllCallbackRegister(WH_KEYBOARD, "LRESULT", "int;wparam;lparam")
  $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD, DllCallbackGetPtr($hStub), 0, _WinAPI_GetCurrentThreadId())
  Local $aAccelKeys[1][2] = [["{ENTER}", $idKey]]
  GUISetAccelerators($aAccelKeys)

  GUIRegisterMsg($WM_COMMAND, WM_COMMAND)
  GUISetState()

  Local $aWordsLeft = $aKeyWords, $sWordSelected
  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        $sWordSelected = ""
        ExitLoop
      Case $idDummy
        $aWordsLeft = WordsLeft(GUICtrlRead($idList), $aKeyWords)
        _ArrayDisplay($aWordsLeft)
        If UBound($aWordsLeft) = 1 Then
          $sWordSelected = $aWordsLeft[0]
          ExitLoop
        EndIf
        $aAllowedChar = EnumerateChar(StringLen(GUICtrlRead($idList)) + 1, $aWordsLeft)
        ;_ArrayDisplay($aAllowedChar)
      Case $idKey
        $sWordSelected = GUICtrlRead($idList)
        ExitLoop
    EndSwitch
  WEnd
  GUIDelete($hGui)
  _WinAPI_UnhookWindowsHookEx($hHook)
  DllCallbackFree($hStub)
  Return $sWordSelected
EndFunc

Func WH_KEYBOARD($iMsg, $wParam, $lParam)
  ;ConsoleWrite("wm_keyb " & Chr($wParam) & "/" & Hex($wParam, 2) & "/" & $wParam & @CRLF)
  If $iMsg = 0 And $wParam <> 27 And $wParam <> 8 And $wParam <> 13 Then
    $bAllowed = _ArraySearch($aAllowedChar, Chr($wParam)) >= 0
    If Not $bAllowed Then Return 1
  EndIf
  Return _WinAPI_CallNextHookEx($hHook, $iMsg, $wParam, $lParam)
EndFunc   ;==>MyProc

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iIDFrom = _WinAPI_LoWord($wParam)
    Local $iCode = _WinAPI_HiWord($wParam)
  If $iIDFrom = $idList And $iCode = $EN_CHANGE And $bAllowed Then GUICtrlSendToDummy($idDummy)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

Func EnumerateChar($iLen, ByRef $aList)
  Local $aChar[UBound($aList)]
  For $i = 0 To UBound($aList) - 1
    $aChar[$i] = StringMid($aList[$i], $iLen, 1)
  Next
  Return $aChar
EndFunc

Func WordsLeft($sInclude, ByRef $aList)
  Local $aLeft = _ArrayFindAll($aList, "^" & $sInclude, Default, Default, Default, 3)
  For $i = 0 To UBound($aLeft) - 1
    $aLeft[$i] = $aList[$aLeft[$i]]
  Next
  Return $aLeft
EndFunc

 

Link to post
Share on other sites

basic structure (msgbox list not coded.... )

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>

MsgBox(0, '', '1) Create your virtual keyboard' & @Crlf & _
              '2) disable all key' & @Crlf & _
              '3) loop [Enable Key List....] to enable/disable required key'  & @Crlf & _
              '4) press enter to display desired item' )

Global $aKeyWords = __Get_Words()
Global $input1, $input2

__ExampleA()
Func __ExampleA()
    Local $hGUI = GUICreate("Filter key", 300, 150)
    GUICtrlCreateLabel("> Input....", 10, 10)
    GUICtrlCreateLabel("> Enable Key List....", 10, 75)
    $input1 = GUICtrlCreateInput("", 10, 35, 280, 25)
    $input2 = GUICtrlCreateInput('', 10, 100, 280, 30)
    GUICtrlSetFont($input2, 11)
    GUICtrlSetState($input2, $GUI_DISABLE)
    GUICtrlSetData($input2, StringUpper(_ArrayToString(__Get_Char($aKeyWords), ' |  ') & @Tab & '(' & __News(GUICtrlRead($input1)) & ')'))
    GUISetState(@SW_SHOW, $hGUI)
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    If _WinAPI_LoWord($wParam) = $input1 And _WinAPI_HiWord($wParam) = $EN_CHANGE Then
        Local $k_newList = ''
        $k_newList = _ArrayToString(__Get_Char($aKeyWords, GUICtrlRead($input1)), ' |  ') & @Tab & '(' & __News(GUICtrlRead($input1)) & ')'
        GUICtrlSetData($input2, StringUpper($k_newList))
    EndIf
EndFunc

Func __Get_Words()
    Local $aKeyWords[] = ["fight", "first", "fly", "third", "fire", "wall", "hi", "high", "hello", "world", "win", "winwait", "winclose"]
    Return _ArrayToString($aKeyWords, '|')
EndFunc

Func __News($oWord)
    Local $aItems[] = ["fly high", "Butterfly", "is linux better than window", "win xp", "win 7", "win 10", _
                          "world cup football 2022", "World Peace Day September 21, 2023", "Autoit winwait", "Autoit winclose"]
    If $oWord = '' Then Return UBound($aItems)

    Local $aCount = 0
    For $i = 0 To UBound($aItems) - 1
        If StringInStr($aItems[$i], $oWord) Then $aCount += 1
    Next
    Return $aCount
EndFunc

Func __Get_Char($oString, $oLetter = '')
    If IsArray($oString) Then Return SetError(1)

    Local $iAlphabet = (($oLetter = '') ? _
                    StringRegExpReplace($oString, '^(\S)|(\|\S)|(\s|\w+)', '$1$2') : _
                    StringRegExpReplace($oString, '\b' & $oLetter & '(.)|(\s|\w+)', '$1'))

    $iAlphabet = StringRegExpReplace($iAlphabet, '[\|]+', '|')

    Local $i_Alphabet = StringRegExp($iAlphabet, '([^|\s])(?!.*\1)', 3)
    If StringRegExp($iAlphabet, '\s', 0) Then
        ReDim $i_Alphabet[UBound($i_Alphabet) + 1]
        $i_Alphabet[UBound($i_Alphabet) - 1] = '{SPACE}'
    EndIf

    If ($oLetter <> '') And StringRegExp($oString, '\b' & $oLetter & '\b', 0) Then
        IF IsArray($i_Alphabet) Then
            ReDim $i_Alphabet[UBound($i_Alphabet) + 1]
            $i_Alphabet[UBound($i_Alphabet) - 1] = '{ENTER}'
        Else
            Local $i_Alphabet[1] = ['{ENTER}']
        EndIf
    EndIf

    Return $i_Alphabet
EndFunc

 

Edited by jugador
Link to post
Share on other sites

Hi folks,

@jugador:
Your example is pretty nice, thank you 👍 . I don't have the same use case as @mutleey has, but I can definitely use this.

@Nine:
Thank you too for your example 😀 .

@mutleey:
I am looking forward how your result will look like, best of luck for it.

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔍 Forum search

🔮 Me on GitHub

💬 Opinion about new forum sub category

 📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to post
Share on other sites

funny question @mutleey
Here's my 2 cents
the keys on the first row of the virtual keyboard are spare,
as you click on the keys, the list of elements is reduced and the disallowed keys are inhibited
The key to the right of the M key, ( ◄ ) deletes the last character in the input field
the key ( ¶ ) confirms the text present in the input field
p.s.
my "graphics keyboard" is a bit spartan, but take this script as one more possible way to achieve your goal

#include <GUIConstants.au3>

Global $aList = _GetCities() ; create the 1D array
MsgBox(0, 'Result', 'You chose ' & _Example($aList, 'choose a city'))


; Pass a 1D array with a list of entries to choose from
Func _Example(ByRef $asKeyWords, $sTitle = '')
    ;                                  00000000001111111111222222222233333333334444444444
    ;                                  01234567890123456789012345678901234567890123456789
    Local Static $aKeys = StringSplit('☺☻♥♦♣♠•◘♪♫1234567890QWERTYUIOPASDFGHJKL ZXCVBNM◄ ¶', '', 2)
    Local Static $aToggleableKey = StringSplit('00000000001111111111111111111111111111111111111000', '', 2)
    Local $aMyMatrix[UBound($aKeys)]
    Local $sString, $hInput, $hList, $bFlag
    Local $sPartialInp, $iPartialLen, $sAllowed, $iNumRows, $sReturn

    $hGUI = GUICreate($sTitle, 401, 600)

    $hInput = GUICtrlCreateInput("", 5, 5, 392, 20, $ES_READONLY) ;  0x0800 )
    GUICtrlSetBkColor(-1, 0XFFFFFF)

    ; Virtual Custom Keyboard
    Local $xPanelPos = 0, $yPanelPos = 30, $nrPerLine = 10, $nrOfLines = 5, $ctrlWidth = 39, $ctrlHeight = 39, $xSpace = 1, $ySpace = 1, $xBorder = 1, $yBorder = 1, $style = -1, $exStyle = -1
    For $i = 0 To $nrPerLine * $nrOfLines - 1
        ; coordinates 1 based
        $col = Mod($i, $nrPerLine) + 1 ; Horizontal position within the grid (column)
        $row = Int($i / $nrPerLine) + 1 ;  Vertical position within the grid (row)
        $left = $xPanelPos + ((($ctrlWidth + $xSpace) * $col) - $xSpace) - $ctrlWidth + $xBorder
        $top = $yPanelPos + ((($ctrlHeight + $ySpace) * $row) - $ySpace) - $ctrlHeight + $yBorder
        $text = $aKeys[$i] ;  + 1 ; "*" ; "." ; "(*)"
        ; create the control(s)
        $aMyMatrix[$i] = GUICtrlCreateButton($text, $left, $top, $ctrlWidth, $ctrlHeight, $style, $exStyle)
    Next

    $hList = GUICtrlCreateList('', 1, 233, 400, 370, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOSEL))
    GUICtrlSetFont(-1, 12, 0, 0, 'Courier New')
    For $i = 0 To UBound($asKeyWords) - 1
        GUICtrlSetData($hList, $asKeyWords[$i])
    Next

    GUISetState()

    While 1
        $Msg = GUIGetMsg()
        Switch $Msg
            Case $GUI_EVENT_CLOSE
                $sReturn = GUICtrlRead($hInput)
                GUIDelete($hGUI)
                Return $sReturn
            Case $hList
                GUICtrlSetData($hInput, GUICtrlRead($hList))
        EndSwitch

        If $bFlag Then
            $bFlag = False
            $sPartialInp = GUICtrlRead($hInput)
            $iPartialLen = StringLen($sPartialInp)

            ; empty the list
            GUICtrlSetData($hList, "")
            $iNumRows = 0

            ; refill the list
            $sAllowed = ""
            For $i = 0 To UBound($asKeyWords) - 1
                If StringLeft($asKeyWords[$i], $iPartialLen) = $sPartialInp Then
                    GUICtrlSetData($hList, $asKeyWords[$i])
                    $iNumRows += 1
                    $sAllowed &= StringMid($asKeyWords[$i], $iPartialLen + 1, 1)
                EndIf
            Next

            ; enable or disable keys
            For $i = 0 To UBound($aKeys) - 1
                If $aToggleableKey[$i] = "1" Then
                    If StringInStr($sAllowed, $aKeys[$i]) Then
                        GUICtrlSetState($aMyMatrix[$i], 64) ; $GUI_ENABLE (64) Control will be enabled.
                    Else
                        GUICtrlSetState($aMyMatrix[$i], 128) ; $GUI_DISABLE (128) Control will be greyed out.
                    EndIf
                EndIf
            Next
        EndIf

        ; 00000000001111111111222222222233333333334444444444
        ; 01234567890123456789012345678901234567890123456789
        ; ☺☻♥♦♣♠•◘♪♫1234567890QWERTYUIOPASDFGHJKL ZXCVBNM◄ ¶
        ;
        ; check if and which key was pressed
        ; and manage actions to be taken accordingly
        For $iKey = 0 To UBound($aMyMatrix) - 1
            If $Msg = $aMyMatrix[$iKey] Then
                Switch $iKey
                    Case 0 To 7
                        ConsoleWrite("Debug: Spare key" & @CRLF)
                    Case 8
                        Beep(500, 70)
                    Case 9
                        Beep(750, 70)
                        Beep(500, 70)
                    Case 47 ; delete rightmost char
                        GUICtrlSetData($hInput, StringTrimRight(GUICtrlRead($hInput), 1))
                    Case 48
                        ConsoleWrite("Debug: Spare key" & @CRLF)
                    Case 49 ; return virtual key ¶
                        ; If $iNumRows = 1 Then
                            $sReturn = GUICtrlRead($hInput)
                            GUIDelete($hGUI)
                            Return $sReturn
                        ; EndIf
                    Case 10 To 46 ; numbers, letters, space
                        GUICtrlSetData($hInput, GUICtrlRead($hInput) & $aKeys[$iKey])
                EndSwitch
            EndIf
        Next

        If $sString <> GUICtrlRead($hInput) Then
            $sString = GUICtrlRead($hInput)
            $bFlag = True
        EndIf
    WEnd
EndFunc   ;==>_Example

Func _GetCities()
    ; source: https://simplemaps.com/data/world-cities
    ;         ----------------------------------------
    ; here a reduced list of the top 159 most populous cities
    ; (for fun I also added my little town (Imperia) just to have a total of 160 cities)
    Local $sCities = ''
    $sCities &= "Tokyo,New York,Mexico City,Mumbai,Sao Paulo,Delhi,Shanghai,Kolkata,Los Angeles,Dhaka,Buenos Aires,Karachi,Cairo,Rio de Janeiro,Osaka,Beijing,"
    $sCities &= "Manila,Moscow,Istanbul,Paris,Seoul,Lagos,Jakarta,Guangzhou,Chicago,London,Lima,Tehran,Kinshasa,Bogota,Shenzhen,Wuhan,"
    $sCities &= "Hong Kong,Tianjin,Chennai,Taipei,Bangalore,Bangkok,Lahore,Chongqing,Miami,Hyderabad,Dallas,Santiago,Philadelphia,Belo Horizonte,Madrid,Houston,"
    $sCities &= "Ahmedabad,Ho Chi Minh City,Washington,Atlanta,Toronto,Singapore,Luanda,Baghdad,Barcelona,Haora,Shenyeng,Khartoum,Pune,Boston,Sydney,St. Petersburg,"
    $sCities &= "Chittagong,Dongguan,Riyadh,Hanoi,Guadalajara,Melbourne,Alexandria,Chengdu,Rangoon,Phoenix,Xian,Porto Alegre,Surat,Hechi,Abidjan,Brasilia,"
    $sCities &= "Ankara,Monterrey,Yokohama,Nanjing,Montreal,Guiyang,Recife,Seattle,Harbin,San Francisco,Fortaleza,Zhangzhou,Detroit,Salvador,Busan,Johannesburg,"
    $sCities &= "Berlin,Algiers,Rome,Pyongyang,Medellin,Kabul,Athens,Nagoya,Cape Town,San Diego,Changchun,Casablanca,Dalian,Kanpur,Kano,Tel Aviv-Yafo,"
    $sCities &= "Addis Ababa,Curitiba,Zibo,Jeddah,Nairobi,Hangzhou,Benoni,Caracas,Milan,Stuttgart,Kunming,Dar es Salaam,Minneapolis,Jaipur,Taiyuan,Frankfurt,"
    $sCities &= "Qingdao,Surabaya,Lisbon,Tampa,Jinan,Fukuoka,Campinas,Denver,Kaohsiung,Quezon City,Katowice,Aleppo,Durban,Kiev,Lucknow,El Giza,"
    $sCities &= "Zhengzhou,Taichung,Brooklyn,Ibadan,Faisalabad,Fuzhou,Dakar,Changsha,Izmir,Xiangtan,Lanzhou,Incheon,Sapporo,Xiamen,Guayaquil,Imperia"
    Return StringSplit($sCities, ',', 2) ; $STR_NOCOUNT (2) = disable the return count in the first element
EndFunc   ;==>_GetCities

 

Edited by Gianni

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...