.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How to get ASCII value of keydown key in wpf?

Posted By:      Posted Date: October 17, 2010    Points: 0   Category :WPF


I'm trying to compare the ASCII values of different keys. I don't know how to get the ASCII values of the keydown key. I've read blogs in forums also, but I don't find helpful to me. I can't find e.keycode or e.keyvalue in the keyeventargs event.I'm using visual c# 2010 and wpf development.

Any help is appreciated.



View Complete Post

More Related Resource Links

Encoding.ASCII.GetString(bytes) return string with not expected

Example   byte[] bytes = {  0x36,0x92,0x30,0x94}; string rs=  Encoding.ASCII.GetString(bytes) ; //result rs = ?60?   Is Wrong Result; Result Right is     '60". So this function should fix to properly decode two symbols ' and " Code ASCII ' is 0x92,Code ACII for " is  0x94

KeyDown event on a Form is not firing for STX and/or ETX

I'm using a wireless barcode reader that's inputting data using HID. I've configured it to wrap the output between STX and ETX (0x02, 0x03), however, i never get any KeyDown event generated when those keys are sent from the device, the barcode keys are sent just fine but not STX and ETX.

Sendkeys.SendWait Method for ASCII Punctuation


I am using Sendkeys.SendWait method in my project for sending characters, using unicode code points, to the Office Applications in Windows XP, Windows Vista and Windows 7. In this method, the unicode code point for Devnagari Characters are working nicely but the unicode code point of English Symbol such as Comma ( , ) is not working in Windows Vista and Windows 7 but it is working properly in Windows XP. It generates an InvalidArgumentException (Queue Empty) for the code point of Comma in Vista and 7.The code point for Comma is '\u002C'.  

Could anyone tell me that why it is throwing an error only for Comma in Windows Vista and Windows 7?

Keydown and IE Autocomplete + Button Click


I have 2 controls: Text1 nd a button.

On Text1 I have added attribute OnKeyDown check to see if user hit enter key and then click Button.

Text1.Attributes.Add("onkeydown", "jCheckEnter(document.all." & Enter.ClientID & ")")

So I start typing Cl into text box and I have 3 options that come in the drop-down with the auto complete
Clothing Line

I use my down arrow and select clothing line and then and then the Enter key which triggers the jCheckEnter java script code

function fnTrapKD(btn){
    if (document.all){
       if (event.keyCode == 13){
          event.cancel = true;

Code above triggers server side code and when I check the value in Text1 it shows cl and not clothing line.  When I hit the enter key to select the value from auto complete it triggers the Enter as it should but the value in the text box is wrong...It just pulls what I actually typed, not what I selected from the auto complete drop down.

At this point when I hit the Server Side Code

When I type in these text boxes the auto complete works as it should.


Pondering ASCII ordering in a string comparison



The following query on SQL Server:

Select case when '9:9' < '99' then 1 else 0 end
returns 1

Given, according to http://asciitable.com/ ':' comes after '9' I am surprised that the above query does what it does. Then again I'm clearly making a wrong assumption somewhere.

Can anyone explain this?




http://sqlblog.com/blogs/jamie_thomson/ | @jamiet | About me
Jamie Thomson

How do I create an XML file from a text file containing simple ascii data? Put another way, how do I


Im trying to take a text file I downloaded from the US Census Bureau website and transform it into an XML file. It is what the Census Bureau calls a ZCTA file. The schema of the file I have reposted as follows:

ZCTA File Record Layout

The ZCTA file contains data for all 5 digit ZCTAs in the 50 states, District of Columbia and Puerto Rico as of Census 2000. The file is plain ASCII text, one line per record.

  • Columns 1-2: United States Postal Service State Abbreviation
  • Columns 3-66: Name (e.g. 35004 5-Digit ZCTA - there are no post office names)
  • Columns 67-75: Total Population (2000)
  • Columns 76-84: Total Housing Units (2000)
  • Columns 85-98: Land Area (square meters) - Created for statistical purposes only.
  • Columns 99-112: Water Area (square meters) - Created for statistical purposes only.
  • Columns 113-124: Land Area (square miles) - Created for statistical purposes only.
  • Columns 125-136: Water Area (square miles) - Created for statistical purposes only.
  • Columns 137-146: Latitude (decimal degrees) First character is blank or "-" denoting North or South latitude respectively

Columns 147-157: Longitude (decimal degrees) First character is blank or "-" denoting East or West longitude respectively

All I want to do is produce an XML file with t

ASCII string to integer grouping equivalent?


Hi I have been trying unsuccssfully to convert a column of data (mycolumn) from a table (mytable)  that has ascii character strings comprised of characters numbered from 0-255. I need to be able to group the numeric values for each ascii string from each record, into what I call an integer group and write that value back to a different column for each respective record in the table. But, I can't figure out how to modify the following Microsoft code to perform this:



-- Create the variables for the current character string position 

-- and for the character string.

DECLARE @position int, @string char(15)

-- Initialize the variables.

SET @position = 1 

SET @string = 'Du monde entier' --here I don't know how to pass a selected column to the @string

WHILE @position <= DATALENGTH(@string) --here I need to know how to loop through each records ascii string and group the values


 SELECT ASCII(SUBSTRING(@string, @position, 1)),

  CHAR(ASCII(SUBSTRING(@string, @position, 1)))

 SET @position = @position + 1


SET NOCOUNT OFF -- then down here somewhere I need to write each converted string to integers back to the myintegerGroup column


The output from above is below, But I need grouped examp: Du monde entier => 681173210911111010010132101110116105101114


Convert text from UTF8 to ASCII



I'm trying to convert text from UTF8 to ASCII.

I need to generate a text file with ASCII encoding. But when I create the file, special caracters are wrote  with unknown format.

Could any one say what I'm doing wrong  in the code bellow?


FileStream textStream = File.Open(caminhoArquivoTexto, FileMode.Create, FileAccess.Write);

StreamWriter textWriter = new StreamWriter(textStream, Encoding.ASCII);

StringBuilder registro = new StringBuilder();

registro.Append("Otávio Camaçarão"); //Name with special caracters

ASCIIEncoding ascii = new ASCIIEncoding();
byte[] byteArray = Encoding.UTF8.GetBytes(registro.ToString());
byte[] asciiArray = Encoding.Convert(Encoding.UTF8, Encoding.ASCII, byteArray);
string finalString = ascii.GetString(asciiArray);


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend