Solved

How to Use KeyChar using C#

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with converting data format in xml file using VB.NET 11 54
Tool Box 2 35
ASP.NET 5 Templates 2 66
How to add <appSettings> to the webconfig file 2 21
A short article about problems I had with the new location API and permissions in Marshmallow
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

16 Experts available now in Live!

Get 1:1 Help Now