Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:34:36+00:00 2026-06-17T09:34:36+00:00

I have a application that reads data from health cards and parse them for

  • 0

I have a application that reads data from health cards and parse them for basic info like D.O.B., Health Card #, and names. Right now, I have a textbox that takes input from the card swiper and it works great, but I feel there could be a better approach for this.

I want to have a keyboard listener in the background of the application that captures input from the card swiper and parse the data without the need of a textbox. I figure I’ll need a loop function in the Form1_Load that actively listens for keyboard inputs, prepare a buffer for the input, and then when a carriage return is detected, go ahead and parse the buffered data. When the parsing is done, clear the buffer.

My problem is I’m relatively new to C# and I don’t know what I should use for listening to keyboard inputs without a textbox. Could someone point me in the right direction?

Here’s my code in case if anyone’s interested: http://pastebin.com/q6AkghvN

Just a note, I followed the credit card swipe guide from
http://www.markhagan.me/Samples/CreditCardSwipeMagneticStripProcessing and modified it slightly for my usecase.

— EDITED —

Thanks Paul and everyone else for their help!

Here is my solution if anyone is interested:

private void frmMain_KeyPress(object sender, KeyPressEventArgs e)
    {
        lblStatus.Text = "Reading Card...";
        lblStatus.ForeColor = Color.Blue;
        if (e.KeyChar != (char)Keys.Enter)
        {
            buffer += e.KeyChar;
        }
        else
        {
            lblStatus.Text = "Parsing Card...";
            if (buffer.Contains('^') && buffer.Contains(';') && buffer.Contains('='))
            {
                try
                {
                    string[] cardData = buffer.Split(';');
                    string[] caretData = cardData[0].Split('^');
                    string[] nameData = caretData[1].Split('/');
                    string[] equalData = cardData[1].Split('=');
                    tBoxHealthCardNumber.Text = equalData[0];
                    tBoxDateOfBirth.Text = FormatBirthday(equalData[1]);
                    tBoxFirstName.Text = TrimName(nameData[1]);
                    tBoxLastName.Text = TrimName(nameData[0]);
                    tBoxDateTimeScanned.Text = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm");
                    e.Handled = true;
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                lblStatus.Text = "Error Reading Card";
            }

            buffer = "";
            lblStatus.Text = "Ready";
            lblStatus.ForeColor = Color.Green;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:34:37+00:00Added an answer on June 17, 2026 at 9:34 am

    If you add a key handler to the form you will not see the key presses when focus is on a control, e.g. a textbox. For the form to see the key presses even when there is a focused control, you must also enable the KeyPreview property.

    You can then add a handler for KeyDown, KeyPress and/or KeyUp on the form as you desire to receive these events.

    As you can read in the documentation to KeyPreview, if you set the Handled property to true, you can prevent the event from being subsequently sent to the focused control, i.e. you can hide certain key events from being seen by the focused control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Android native java application that reads data from a Bluetooth
I have application reads in data from text file. Recently I realized that I
I have a MVC application that reads some data from a database and loads
I have an application that reads string data in from a stream. The string
I'm writing an application that reads data from a local db and display them
I have an small ASP.NET application that reads data from a table and sends
I have an application that reads the data in UTF-8 format from the server,
I have a simple application that reads data in small strings from large text
I have an application that reads data from a com port using javax.comm. The
I have a Django application that reads data from a web API and puts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.