Traversing listboxes via the keyboard

Arjen Markus (7 february 2003) This page is meant to discuss what people expect from traversing listboxes via the keyboard and how to implement this:

  • Besides the Page-Up and Page-Down keys, I often want to just type "k" to go to the first or next item that starts with "k".
  • If you do this, what are the consequences for the selection that may be in progress?
  • Does it make sense? Or should this merely be a facility to move the listbox to that particular item.
  • As listboxes do not often get the keyboard focus by default, how do we enable such a feature?
  • This could be a useful feature in Tklib - any one wants to give it a try?

DKF (same day) - This is trickier than it looks.

If we ignore for the moment what is involved when handling selections of more than one thing at once, we can easily support this sort of thing by making it so that pressing a letter (or other character which is a prefix) makes a member starting with that letter visible and selected. That's fairly easy to do, and works particularly well (IMO) when the list is sorted.

However, if you have several entries starting with that letter, you have a bit of a problem. Do you always select the first or do you select the next one after the current selection?

Another thing to think about is what happens if people try to type several letters giving a prefix of an entry; I've done this in the past even where I've known it won't work, so it is definitely intuitive behaviour on the part of users! Getting that working right is tricky indeed, because you have to distinguish between someone typing a prefix and someone pressing one letter, thinking for a while, and then pressing another letter to begin another search. I'm not at all sure I have a good solution to that, though perhaps it would be best if you did this and have non-key events cancel the accumulation (i.e. so you start from the beginning of the prefix again with the next key press) and also have some kind of timeout. If you coupled this to an entry (combobox-style?), perhaps the timeout would be less necessary in some way?

Oh well, food for thought!


Example code (a font-selection dialog) http://people.man.ac.uk/~zzcgudf/tcl/mwidx.html#fontdlg


Please insert your comments and thoughts!