Jump to content
Sign in to follow this  

Input field with hinting

Recommended Posts


Hi there,

For a program I'm writing I'd like to use an input with something that functions like Google hints, but a lot more complicated...


- While typing in the input field, the first result is picked from a list of possible values (using pattern matching, e.g. typing 'Do' matches 'John Doe').

- No mouse can be used, so the hint has to be displayed in the same input field as where the user is typing.

- The part that is hinted is displayed in grey, the typed part in black (e.g. when 'Do' is typed: 'John Doe')

My questions:

- Does this seem possible to make at all?

- If so, any hints on how to do this?

- Can you see alternative/better ways to standardize typed input or match it to a list of values without using a mouse?

Thanks in advance for your response!

Best regards,


PS: Here the background for what I'm asking:

I'm writing something to register attendance at my work.

This is to be able to see if everyone is safe in case of emergency.

The program is goin to run on a machine with keyboard and RFID-scanner (with keyboard emulation to keep it simple ;-) but no mouse.

Employees have an RFID-tag to check in or out and don't use the keyboard at all.

Guests will also check in or out with tags, but the program will ask the guest to enter his name, company name and whom they are visiting.

For this last part (whom are they visiting) I'd like to be able to use hinting.

So when something is typed in the input field it is compared to all employee names, and the best matching one is displayed.

The guest can then complete/accept with ENTER or just continue typing.

Share this post

Link to post
Share on other sites

It can be done but the method used will depend on how the data will be stored. If they are in, or can be put into, an array then it can be done using _ArrayFindAll() with $iPartial set to 1. It may get a bit trickier for Guests but that can be worked out too.


Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver: - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post

Link to post
Share on other sites

Hi GEOSoft,

Thanks for your reply.

I guess matching what is typed to the list of possible value wasn't the hard part...

But how to make the input field display the hinted part in a different color?

Is that even possible?



Share this post

Link to post
Share on other sites


With my previous posting it occurred to me that I did search the forums before, but not for 'multiple colors in edit' and the like.

Searching again led me to posts with 'use rich edit controls' etc...

Why didn't I think of that before? :-p

Anyway, looking into rich edit controls now...



Share this post

Link to post
Share on other sites

So, after some tinkering I have it working like I want to.

Thanks GEOSoft for helping me out >_<

If someone else needs hinting in a search field:

#include <GuiRichEdit.au3>
#include <GUIConstants.au3>
#include <Array.au3>

Global $hRichEdit

Global $employeelist[20] = ["Corina Reagan","Melissa Corina","Debra Corina","Diana Brianne","Elise Tamela","Reagan Jonquil","Deidra April","Kayleah Christmas","Zoe Amber","Zoe Bess","Lexy Tanya","Tamela Melissa","Selina Kailey","Mabel Louisa","Opal Sophie"]
Global $hint, $hint1, $hint2



; Search in an array for a matching pattern and display this as a hint
Func WriteHint($searchval)

; The contents of the edit are partly hinted, but we want to search only based on what the user actually typed
; So based on hints from the previous call to this function we delete the hinted part
if stringlen($hint1) <> 0 then $searchval = StringMid($searchval, StringLen($hint1)+1)
if stringlen($hint2) <> 0 then $searchval = StringLeft($searchval,StringLen($searchval) - StringLen($hint2))

; Search the array for something that matches what was typed
$result = _ArrayFindAll($employeelist, $searchval, 0 , 0, 0, 1)
$hint = ""
if IsArray($result) then $hint = $employeelist[$result[0]]

; Create the first part of the hint (to be displayed in front of what user typed)
$hint1 = StringLeft($hint, StringInStr($hint, $searchval)-1) 

; Create second part of the hint (to be displayed behind what user typed)
$hint2 = StringRight($hint, Stringlen($hint)-Stringlen($hint1 & $searchval)) 

; Create an RTF-string composed of hints and user input
$txt = "{\rtf1\ansi{\colortbl;\red128\green128\blue128;}\cf1\f0\fs20 "& $hint1 &"\cf0\b "& $searchval &"\cf1\b0 "& $hint2 &"}"

; Set cursor to correct location (where user was typing)
EndFunc ;==>WriteHint

Func Main()
    Local $hGui, $iMsg
    $hGui = GUICreate("Rich Edit Example", 500, 550, -1, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 480, 25, _

$old = ""

    While True
        ; If contents of the edit changed we want to see if we can show a hint...
        $new =  StringUpper(_GuiCtrlRichEdit_GetTextInLine($hRichEdit,1))
        if $old <> $new then WriteHint($new) ; 
        $old = $new
        $iMsg = GUIGetMsg()
            Case $iMsg = $GUI_EVENT_CLOSE
EndFunc   ;==>Main

Best regards,


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