문제

I am developing application on Windows Mobile 6 (uses compact framework). The application uses a barcode scanner. I want to implement keyboard shortcuts in the menu. I have implemented a keypress event in the menu so that if the user presses 1 the first menu item is opened and so on. But my problem is that if the user scans the barcode with the device while the application is in the menu, the application gets the barcode read by the scanner and translates it to keypresses. As I have keyboard shortcuts implemented in submenus as well, this means that if the user scans the barcode in the menu the application moves between menus.

I am not 100% sure but it seems that devices I use have barcode readers as "keyboard wedge" and when they are that kind you get text from them as if the user was typing it from the keyboard.

This is how keypresses in the menu are implemented:

private void mainList_KeyPress(object sender, KeyPressEventArgs e)
    {
            switch (e.KeyChar)
            {
                case (char)Keys.D1:
                    productRequestBtn_Click(sender, e);
                    break;
                case (char)Keys.D2:
                    warehouseBtn_Click(sender, e);
                    break;
                case (char)Keys.D3:
                    inventoryBtn_Click(sender, e);
                    break;
                case (char)Keys.D4:
                    ordersBtn_Click(sender, e);
                    break;
                case (char)Keys.D5:
                    discountBtn_Click(sender, e);
                    break;
                case (char)Keys.D6:
                    intakeBtn_Click(sender, e);
                    break;
                case (char)Keys.F1:
                    Close();
                    break;
            }
    }

I have tried different ways to implement it but haven't managed to solve my problem.

If someone has any idea how to either change keyboard shortcuts implemented in menus, block a barcode reader or anything that might work in the described case, I would really appreciate it.

올바른 솔루션이 없습니다

다른 팁

Yep, using the barcode scanner sdk would be the best solution.

If want to avoid to code that OEM specific stuff you may workaround your issue using the keyboard wedges pos- and/or pre-amble settings.

Most if not all of the wedge implementations support adding a sequence before and after the scanned data, this may be called preamble and postanble. Using this feature you can change your code and for example disregard and keypresses if they start with * and end with # for example. If so, just add * as preamble and # as postamble in the wedge setup of your device. Using this technique you have to remove the chars in your barcode input field before you go on and validate/process the barcode data.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top