473,813 Members | 3,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2500
How about (below, use [Ctrl]+[Break] to end):

using System;
using System.Text;
static class Program
{
static void Main()
{
Console.TreatCo ntrolCAsInput = true;
while (true)
{
ConsoleKeyInfo key = Console.ReadKey (true);
WriteChar(key.K eyChar);
}
}
static void WriteChar(char c)
{
char[] chars = { c };
byte[] bytes = Encoding.UTF8.G etBytes(chars);

foreach (byte b in bytes)
{
Console.Write(b .ToString("x2") );
}
Console.WriteLi ne();
}
}
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.WriteAllTe xt(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.Diagnost ics;
using System.IO;
using System.Threadin g;
using System.Windows. Forms;
static class Program
{
static void Main()
{
Process proc = Process.Start(" notepad.exe");

Console.WriteLi ne("Please ensure notepad is active!");
Thread.Sleep(50 00);

string INPUT = @"some~
text~
that
might{TAB}hic
be~
on~
different
lines";
using (TextReader reader = new StringReader(IN PUT))
{
string line;
while ((line = reader.ReadLine ()) != null)
{
SendKeys.SendWa it(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
7092
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: sébastien. The second character is not an ascii one and when i try to encode the path that contains this name in utf-8,
6
2787
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 value given its utf8 value? Rgds, Sam
12
4119
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 mappings though, and it seems like a shortcoming of the .NET framework: When I see Unicode value 0x10400, I'm supposed to map it to value 0x10428. This list goes on (the left colulmn is the existing value, the right column
5
2557
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 now I need it to work on Russian computers and I realized that the application should be converted to Unicode to work in Russian. I am totally new to .NET so I'm not sure of this, but I read somewhere that if converted my apllication to .NET...
6
6618
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 performance loss using (multibyte) UNICODE vs (single byte) SQL_ASCII/LATINxxx character encoding? (In terms of extra data, and searching/sorting speeds).
29
3532
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 range(128) >>>
6
13895
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 character in streamreader and streamwriter. How unicode and utf chacters are stored.
17
4535
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 functions do this on occasion. This leads to different behaviour across platforms and makes it unnecessarily difficult to properly support all languages. To solve this I propose Python's unicode type using UTF-16 should have gaps in its index,...
2
2826
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 needs to be appended to is dbf file type, I wrote a dbf writer so adding data on the fly is not a problem, the problem is trying to get the correct encoding. The barcode utility that we purchased
2
3610
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 see the corresponding characters displayed in an excel file. How could I go about doing that ? vector<stringunicodevalues; // has values 0041, 0042, ... 0410 etc. (hexa decimal values)
0
10665
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10420
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10139
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9221
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.