USBhost keydown events to slow for application

Im trying to build a program to read a magnetic card from a cardreader simulated as a keyboard. However for the time being every char is its own event and its taking around 1.100milisec to 1.3milisec to read the card, this is abit to high. The complete cycle is around 1500 milisec and what we are aiming for with this application is around 600-700 milsec.

I was wondering if there was any way to get a string in faster then with keydown events. Or perhaps a way to speed them up.

void _keyboard_KeyDown(USBH_Keyboard sender, USBH_KeyboardEventArgs args)
        {
            if (args.KeyAscii == ';' || args.KeyAscii == '%')
            {
                Card = null;
                record = true;
            }
            else if (args.KeyAscii == '?')
            {
                record = false;
                Send();
                Card = null;
            }
            else
            {
                if (record == true)
                {
                    Card += args.KeyAscii;
                }
            }
        }

The send function is just to communicate with the server to get a response on the cards.

What reader do you use?
Can you use some other protocol instead of “Keyboard Emulator”? I think it will be a lot of faster…

Hi,

Declare Card only once, as an array of char, and fill it using an index.
Convert to string only when all is ready.

Have you tried to measure the responsiveness of the keydown event itself ?

I agree with @ Steph, if handling the key presses is your critical timing point, make that as quick and as lean as possible. Don’t ever do string operations and get in, add the press to a buffer, and get out. If you need, use the terminator to flag another thread to start the processing of the compiled data.

Bypassing the added overhead of Gadgeteer might also help improve performance.