Main Site Documentation

Moving keyboard characters


#1

I have several textboxes (name, address, etc) to be filled in by typing on a keyboard. I have a keyboard routine that gets fired with each press ogf a key:

[quote] static void CharDown(USBH_Keyboard sender, USBH_KeyboardEventArgs args)
{
string nuchar = args.KeyAscii.ToString();
Debug.Print(nuchar);

        if (selector==1) TestTexBox1.Text = TestTexBox1.Text + nuchar; //append incoming to textbox1
        if (selector == 2) TestTexBox2.Text = TestTexBox2.Text + nuchar; //append incoming to textbox2
        if (selector == 3) TestTexBox3.Text = TestTexBox3.Text + nuchar; //append incoming to textbox3
    }[/quote]

However, since there are many textboxes it seems a bit backwards to try to figure out where to send the chars (to various textboxes) from within this routine, perhaps by setting a selection parameter in the main routine. Is this the proper arrangement?


#2

Cant give you a solution, but yep that seems the wrong approach. Take a look at something like Pyxis2 or even Glide and see how they do it - you should find they have a similar issue with their soft keyboard.


#3

Thanks, I may take a look, though that’s a big ship to crawl around. My understanding is that each routine that sets up a textbox must subscribe to the CharDown event, its just not clear how that event knows where to put the data (unless i cheat and just directly tell it where, as I showed). Does sender provide this location?


#4

The way I approach it is to have a “focused” object on a form. So when input comes in it is directed to that object. If the object is null the event bubbles up to be caught elsewhere.


#5

by directed, do you mean just always use its name directly, such as

focusedBox.text=append(nuchar);


#6

No. The form has a variable say _focused that you assign te focused control to. Then when input is gathered form._focused gets the event


#7

Do you mean something like:

            Control theFocusedControl;

            theFocusedControl = textBox1;    // the control that is to be modified by the event