Combo Box Key Combination

Jan Schenkel janschenkel at yahoo.com
Wed Mar 26 01:44:46 EDT 2008


--- Bill Vlahos <bvlahos at mac.com> wrote:
> I have a combo box button in a series of fields. The
> user can tab into  
> the field part of the combo box button and type what
> they want or they  
> can mouse click the arrow part of the button and get
> the list of items  
> to pick from. Usually the user will pick from the
> list but this gives  
> the option to enter something not in the list.
> 
> Is it possible to allow the user to only use the
> keyboard for this?  
> For example, once the user tabs (or clicks) in the
> field part of the  
> button could they press a key (such as Enter), then
> navigate the items  
> with the arrow keys and then tab out?
> 
> An even better solution would be as the user types
> in the field part  
> of the button it autofills if there is a choice that
> matches. I've  
> seen some web browsers do this for popup fields and
> it is pretty  
> convenient.
> 
> This way they wouldn't have to take their fingers
> off the keyboard but  
> still get the option to pick from the list.
> 
> I don't see anywhere in the docs that describe
> something like this.
> 
> Thanks,
> Bill Vlahos
> 

Hi Bill,

The following script can be a start for "claivoyant"
comboboxes:
##
local sLineOffset, sNewSelectionStart

on keyDown pKey
  local tLabel, tNewLabel, tSelStart, tSelEnd
  --
  put the label of me into tLabel
  put word 2 of the selectedChunk into tSelStart
  put word 4 of the selectedChunk into tSelEnd
  -- prefab the new label
  if tSelEnd < tSelStart then
    -- user is inserting a character
    put (char 1 to tSelStart of tLabel) & \
        pKey & \
        (char (tSelStart + 1) to -1 of tLabel) \
        into tNewLabel
  else
    -- user is replacing a selection
    put (char 1 to (tSelStart - 1) of tLabel) & \
        pKey & \
        (char (tSelEnd + 1) to -1 of tLabel) \
        into tNewLabel
  end if
  -- check the new label
  put lineOffset(tNewLabel, the text of me) into
sLineOffset
  if sLineOffset = 0 then
    -- not in our list of allowed choices
    beep
  else
    put tSelStart + 1 into sNewSelectionStart
    pass keyDown
  end if
end keyDown

on keyUp pKey
  if sLineOffset > 0 then
    set the label of me to line sLineOffset of the
text of me
    select char sNewSelectionStart to -1 of me
  end if
end keyUp
##

This does the sort of type-ahead you see in Excel,
browsers, etc. However, it is incomplete if you're
looking to limit the user to just the items in the
list: you'll have to add appropriate handlers for
'pasteKey', 'cutKey', 'deleteKey' and other events.

Hope this gets you started,

Jan Schenkel.

Quartam Reports & PDF Library for Revolution
<http://www.quartam.com>

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ



More information about the Use-livecode mailing list