Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to Use KeyChar using C#

Posted on 2009-05-20
2
Medium Priority
?
1,693 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 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Preface: This article is part of a series focused on cross platform mobile app development (specifically Android and iOS) using the Alloy framework and Titanium Studio made by Appcelerator (https://www.appcelerator.com/). This article presumes a wor…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

972 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