I have a combobox which has two items: east and West (East shows by default).
I added a keyDown event handler to have it switch to west by typing w or W. It goes like this:
If asc(Key)=87 or asc(Key)=119 Then
How can I mask whatever I type (w or W)? As it is it works but it shows wWest or Wwest which is not what it should do.
If key = "w" then
me.ListIndex = 1
me.Text = "West"
ElseIf key = "e" then
me.ListIndex = 0
me.Text = "East"
Xojo string comparison is case-insensitive, so you can write this as
if Key = "W" Then
If you return True from KeyDown, the character will not be added to the ComboBox.
I tried like you said Tim but I still get the w character before the word “West”. Maybe I’m missing something, I assigned the event handler to the specific combobox and in so doing it will work only when it gets focus, that’s probably why I still get an extra “W” printed in the box.
Do you think I should assign the KeyDown event higher in the hierarchy (like in the window owning the combobox)?
you forgot Return True ?
what I have written above works well (could test only in Linux at the moment).
whether uppercase or lowercase
If the menu can only have two values and it starts with a default, why not use a PopupMenu instead. It’ll still respond to key presses.