Ah. OK. I had seen those resources, but I was hoping there was a simpler way. Although, now that I've delved into them, they're not complicated, just unfamiliar. I'm sure I'll become more familiar with the Reflection library and Java over time.
So, I almost posted the following question: "Can you show me how to know if the Shift key (or any other modifier key)?" But I decided to start digging. I'm going to be here a while, so I might as well do some "deep learning."
So, first, I output e to the Log(). It looks like "code" contains "TAB, shiftDown," but the output doesn't show the "shiftDown." I realized shiftDown was a property, not a value of code! So, I was able to grab that and the target, and came up with this:
Sub KeyPressed_Filter(e As Event)
Dim jo As JavaObject = e
Dim eventtype As String = jo.RunMethodJO("getEventType",Null).RunMethod("getName",Null)
If eventtype = "KEY_PRESSED" Then
Dim target As B4XView = jo.RunMethod("getTarget",Null)
Dim keycode As String = jo.RunMethod("getCode", Null)
Dim shiftDown As Boolean = jo.RunMethod("isShiftDown",Null)
If target = txt_FirstName Then
If keycode = "TAB" And shiftDown Then
txt_ZipCode.RequestFocus
e.Consume
End If
Else If target = txt_ZipCode Then
If keycode = "TAB" And Not (shiftDown) Then
txt_FirstName.RequestFocus
e.Consume
End If
End If
End If
End Sub
Is my use of e.Consume correct here? I assume it means, "We've handled this, no need for the OS to process it."
Seems to be right!
This is doing exactly what I want. The user is constrained to the form until an exit key is received (which I haven't programmed yet). I'll have to intercept the Enter key eventually, to solidify the form input, and maybe Esc to cancel it...
Is there a better way to handle this? Otherwise, I think I'm good to go! WOo hoo!