Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to Use KeyChar using C#

Posted on 2009-05-20
2
Medium Priority
?
1,678 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
abel earned 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you are anything like me, you install many apps on your phone and have your life on it, sometimes literally.  When I bought my current phone, a Samsung Galaxy S5 from Verizon, they were only selling the versions with 16 GB internal.  I didn't rea…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

704 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