Solved

How to Use KeyChar using C#

Posted on 2009-05-20
2
1,639 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RLDC Reporting in Visual studio 11 28
Updating specific fields only in MVC/Entity controller 2 18
VS 2017 18 29
Need syntax help building hyperlink 2 20
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Let me explain this picture a little bit.  First, in case you haven't already guessed, you are looking at my 2 phones, an Android Samsung Galaxy S5 on the left and an iPhone 5 on the right.  They are on their respective cradles on my desk.  But, you…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 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