Trouble capturing ListBox keystrokes

Hi Everyone,

Newb here, still evaluating Xojo for upcoming project.

I’m trying to enable keyboard navigation in a multicolumn ListBox, specifically the Tab and Enter keys. The ListBox.CellKeyDown event’s Key parameter is only returning 0 for Tab, Enter, arrow keys, etc., thus making it (seemingly - I’m probably doing something wrong) impossible to detect which navigation key the user pressed.

What’s the trick to capturing the actual key that the user pressed? Also, I looked, but couldn’t find any example of editing a ListBox “record” like one would with a true data grid in other programming tools like Delphi, .NET WinForms, etc.

Thanks!

Please post a sample of how you are doing this so we can see what might be wrong

Tab is ChrB(09)
Enter is ChrB(03) or ChrB(13) … Enter and RETURN
Arrows are ChrB(28) to ChrB(31)
BackSpace is ChrB(08)

In the keypressed event
select case details.charCode
case details.keyEscape

case details.keyBackspace, details.keyDelete

end select

Does work for desktop, but not in web.

Dave, John,

Thanks - using ChrB() gets me what I need. But John - I don’t see a KeyPressed event, but it looks like that’s because this I’m working on a OSX desktop app, not a web app.

sorry … KeyDown on the desktop

John,

I’m getting an error that says details.charcode does not exist. details is not a parameter for the event, obviously.

The code he posted was obviously cut out of one of his own projects, and neglected to provide the “details” as to what “details” was

Easiest to just use CHRB() in the KEYDOWN event

“Details” is the way WE handles keystrokes. It will probably be back-ported into desktop at some point. The code John posted was web, not desktop. The two hanlde keydown completely different.

Guys, let ask the question another way. Is there some example code or a demo that demonstrates the capturing of all navigation keystrokes in a ListBox for Win/OSX desktop apps?

FUNCTION keydown(key as string) as boolean
SELECT CASE ASCB(key)
case 3,13
 ''' do what ever the ENTER or RETURN key should do
case 9
''' do what ever the TAB key should do
case 8
''' handle a backspace
case 28
''' handle back arrow
case 29
''' handle right arrow
case 30
''' handle up arrow
case 31
''' handle down arrow
case else
return false ' let OS handle the key, as it is not one you want to handle special
end select
return true ' you handled the key.... OS will ignore it now

END FUNCTION

Dave,

Thanks so much - just what I was looking for. Now, for just one more question on this topic: what about Shft-Tab (to go backward)? :slight_smile:

[quote=29415:@Alex Sharp]Dave,

Thanks so much - just what I was looking for. Now, for just one more question on this topic: what about Shft-Tab (to go backward)? :)[/quote]

[code]SELECT CASE ASCB(key)
case 9
If keyBoard.ShiftKey Then
’ Go back
Else
’ Go Foreward
End if
Case …

End Select

[/code]

Thanks Karen. I didn’t know there was a global “intrinsic” object called KeyBoard :slight_smile: