Solved

How to Use KeyChar using C#

Posted on 2009-05-20
2
1,625 Views
Last Modified: 2013-12-21
I have item number which all have "\" at the begging of them. When I scan it and wlak thru the code, it chnages the "\" to a "$" sign and then strips out the other letter after it.

\Design
|Install
/Office

The slash can be a forward slash or a  back slash. Also it will not scan anything with a * on it.

*Instal
*Office

I'm using KeyChar to check the barcode
if (!Char.IsLetterOrDigit(e.KeyChar) && e.KeyChar != '\b')

{

 

}

e.Handle = true;

Open in new window

0
Comment
Question by:daruffin
2 Comments
 
LVL 39

Accepted Solution

by:
abel earned 250 total points
ID: 24563941
Are you within a KeyPressEvent? I just tested on a simple form and by pressing the keys you mentioned I could not create the same behavior you experience. There are, however, keys that are not recognized by KeyChar: http://msdn.microsoft.com/en-us/library/system.windows.forms.keypresseventargs.keychar(VS.80).aspx.

You may try a lower-level event like KeyDown or PreviewKeyDown and check the KeyCode and Modifier properties. It should reveil more information. The KeyCode for the "*" is Keys.D8 plus Shift modifier on my keyboard (will be different for yours). Just place a Debug.WriteLine to find out the relevant keycodes.

The change from "\" to "$" is likely because of a mismatch in selected keyboard layout (esp when events originate from somewhere else). You should set the keyboard layout though Windows International Settings to the same keyboard layout you are using for this input (may be different from your real keyboard if input comes from elsewhere).

-- Abel --
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
I recently asked a question (http://www.experts-exchange.com/Programming/Smartphones/Android/Q_28684946.html) about Computer Inventory applications for Mobile Devices.  I was specifically interested in an app I could use on my android phone.  The be…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now