B4J Question Modules - understanding interaction

rspitzer

Active Member
I am trying to understand the relationship between modules. I am a great believer in modules. Anyway, I have built a module that displays a qwerty keyboard - just a basic A to Z layout, with space bar, backspace and cursor movement. The application is tablet based, so no attached keyboard. I use the Java Robot routines to send a key to a Text-field on the screen to show the screen key press. Everything works okay. I built a second module, that only shows a numeric keypad, this module is called onto the screen when needed, also some of the keys on the pad may be swapped for some special function keys. This module works also, with one caveat, when I press a key, (can debug its press etc..) I show no output on the Text-field on the alpha keyboard module. Whats interesting is if I display the numeric key pad first then the alpha keyboard second, then the presses of the alpha keyboard do not show in the Text-field. So this seems to me that there is something I am missing about tying the two modules together. Is this a node problem, the node that is called second has the focus? Is there some missing code problem ie, the numeric keypad is unaware of the alpha keyboard module, since the alpha keyboard module has priority if shown last? So I am not sure where to go next. Is there some generic reference I can look at to understand this relationship?
 

Cableguy

Expert
Licensed User
Longtime User
In your specific case, I woul convert (compile) the classes to libs, just to make it simpler to work with. Search for custom views
 
Upvote 0

rspitzer

Active Member
I did a little more digging to try to figure this out (including re watching the video). I have come to the conclusion this is not a module or class issue. I went back an redid the program so it shows both layouts on the screen side by side from the main module. According to you the form layout is independent of the class or module, so the forms can be called ie.. re usable. I understand that. This issue is my understanding of the what best as I can describe is the focus of the form for input. There is only on text field input, this input is on the first form.The first form shows on the screen and can be touched and shows the appropriate key. If I load the second form on the same screen (this form just shows keys, no text field), also both reside in the same main module, next to the other form, I can touch the keys on that form, but nothing shows in the text field of form 1. The basic question is how do I get the data from the other form to show on the main form.? When I debug the screen and single step from the mouse pressed event on the second form input, I can clear see the animation pf my key press, then a call to a routine (shared by both forms) to use the robot program to basically send a key character to the text field input. The main form works all day, as long as the second form is not shown. I am assuming I am missing some type of focus event???
 
Upvote 0

rspitzer

Active Member
Doing some more digging, I have isolated the problem, yet I don't understand why this is occurring. If I change the definition of the Textfield to Textarea, then both forms work.
Textfield would be ideal. Is there a way of using Textfield in this context???
 
Upvote 0

rspitzer

Active Member
I have attached a small program call keytest. It will display two forms side by side. The left form is made up of a key and a text field. Pressing this key will show the letter "a" in the textfield. The second form only has a letter "b" key. Pressing this key should I was thinking show the letter "b" in the left hand form textfield. This does not occur, I know I must be missing something here.
 

Attachments

  • keytest.zip
    14.6 KB · Views: 189
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I experimented some, it appears the robot only works on the form that has focus, so when the B is pressed it sends the key stroke to form2.
You can get the effect you want by modifying the mouse up event as follows

B4X:
Sub Letter_B_MouseReleased (EventData As MouseEvent)
    bmpbackground = fx.LoadImage(File.DirAssets, "B.png")
    Letter_B.DrawImage(bmpbackground, 0, 0, Letter_B.Width, Letter_B.Height)
  
    'transfer the character to the text field manually
    Dim tf As TextField = frm.RootPane.getNode(0)
    tf.Text = tf.Text  & "b"
    tf.RequestFocus
    tf.SetSelection(tf.Text.Length, tf.Text.Length)
End Sub
 
Upvote 0

rspitzer

Active Member
I assumed it was some type of focus issue, but I don't have enough experience on this platform to come up with a possible solution. I will give it a try, thanks for the diagnosis. I also found that if I change the Textfield to Textarea, that works, but it then requires a bunch of underlying code using string builder to get what I want. That's not a problem for me, I have written a ton of key input routines, using Textfield was a bit more elegant and required less underlying code to get what I wanted. I just found the behavior to be unusual. Anyway thanks again.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…