473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Unicode values

I am not sure where to start on this.

Does someone have a code snippet which will wait for a keypress or
combination keypress & give me its utf8 value?

e.g

ESC // keypress
Ctrl + C // combination keypress

Thanks.
Jun 27 '08 #1
7 2453
How about (below, use [Ctrl]+[Break] to end):

using System;
using System.Text;
static class Program
{
static void Main()
{
Console.TreatControlCAsInput = true;
while (true)
{
ConsoleKeyInfo key = Console.ReadKey(true);
WriteChar(key.KeyChar);
}
}
static void WriteChar(char c)
{
char[] chars = { c };
byte[] bytes = Encoding.UTF8.GetBytes(chars);

foreach (byte b in bytes)
{
Console.Write(b.ToString("x2"));
}
Console.WriteLine();
}
}
Jun 27 '08 #2
Thanks Marc. I'll try your solution momentarily.

If I am using SendKeys to simulate the left arrow being pressed 10 times,
I'd send {LEFT 10}

If I am reading the keystrokes to send to a window from a file, how do
write {LEFT 10} to the source file in the first place?

Thanks.
Jun 27 '08 #3
If I am reading the keystrokes to send to a window from a file, how do
write {LEFT 10} to the source file in the first place?
I might have misunderstood the question, but how about:

File.WriteAllText(path, "{LEFT 10}");

Marc
Jun 27 '08 #4
I might have misunderstood the question,

You might have. Currently, I read the input/source one byte at a time; so if
I read

\r I send {Enter}
\t I send {TAB}

here's my problem

[what to I need to read] I send {LEFT 10}

Thanks for your help.

Jun 27 '08 #5
Well, reading one *byte* at a time is a little dangerous anyway (unless
you know the data is ASCII or another single-byte encoding [UTF8 is not
single-byte for most of the possible chars]).

I'm not entirely sure whether your input is meant to be in plain text,
or SendKeys format; if plain text, and you want to send the literal
"{LEFT 10}", then you need to escape the reserved chars - i.e. any of:
+, ^, %, ~, {, }, [, ], (, )

The rules for this are here:
http://msdn.microsoft.com/en-us/libr...83(VS.85).aspx

If the file is meant to be already in SendKeys format, why do you need
to parse \r etc?

Anyway, you could use StreamReader to read it a line at a time, and send
lines rather than individual characters - although if the file is in
SendKeys format, I think I would not send anything for CR/LF, and just
use it to break up the text - i.e. I might have:
some~
text~
that
might
be~
on~
different
lines

In addition to solving the issue with sending "{", "E", "N", "T", "E",
"}", this would involve fewer IPC calls, so should be quicker.
Marc
Jun 27 '08 #6
like so, but I'm using a string for soruce instead of a file (same
difference...)

using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;
static class Program
{
static void Main()
{
Process proc = Process.Start("notepad.exe");

Console.WriteLine("Please ensure notepad is active!");
Thread.Sleep(5000);

string INPUT = @"some~
text~
that
might{TAB}hic
be~
on~
different
lines";
using (TextReader reader = new StringReader(INPUT))
{
string line;
while ((line = reader.ReadLine()) != null)
{
SendKeys.SendWait(line);
}
}
}

}
Jun 27 '08 #7
Thanks for your help and sample code.

I need to have a clearer grasp of what I am doing, I think.

Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: sebastien.hugues | last post by:
Hi I would like to retrieve the application data directory path of the logged user on windows XP. To achieve this goal i use the environment variable APPDATA. The logged user has this name:...
6
by: S. | last post by:
if in my website i am using the sgml { notation, is it accurate to say to my users that the site uses unicode or that it requires unicode? is there a mathematical formula to calculate a unicode...
12
by: Chris Mullins | last post by:
I'm implementing RFC 3491 in .NET, and running into a strange issue. Step 1 of RFC 3491 is performing a set of mappings dicated by tables B.1 and B.2. I'm having trouble with the following...
5
by: Sonu | last post by:
Hello everyone and thanks in advance. I have a multilingual application which has been built in MFC VC++ 6.0 (non-Unicode). It support English German Hungarian so far, which has been fine. But...
6
by: John Sidney-Woollett | last post by:
Hi I need to store accented characters in a postgres (7.4) database, and access the data (mostly) using the postgres JDBC driver (from a web app). Does anyone know if: 1) Is there a...
29
by: Ron Garret | last post by:
>>> u'\xbd' u'\xbd' >>> print _ Traceback (most recent call last): File "<stdin>", line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in position 0: ordinal not in...
6
by: archana | last post by:
Hi all, can someone tell me difference between unicode and utf 8 or utf 18 and which one is supporting more character set. whic i should use to support character ucs-2. I want to use ucs-2...
17
by: Adam Olsen | last post by:
As was seen in another thread, there's a great deal of confusion with regard to surrogates. Most programmers assume Python's unicode type exposes only complete characters. Even CPython's own...
2
by: JimmyKoolPantz | last post by:
We purchased som software for encoding a barcode. We want to automate the process of converting a number to a readable barcode. However, I am having a few issues. The file that the barcode...
2
by: KK | last post by:
Hello all, There could be flavors of this question discussed in the past, but I could not really make a head/tail out of it. I have bunch of unicode values stored in a string array and I want to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.