I am seeking a method to detect if ASCII Control Characters are pressed. My code currently shown here is not working too well i suspect. -
-
private void Transmitted_KeyDown(object sender, KeyEventArgs e)
-
{
-
if (e.Modifiers==Keys.Control)
-
{
-
test = (char)e.KeyCode;
-
}
-
}
-
10 8509
"ASCII control characters" such as an ASCII 05 "Enquiry", or an ASCII 23 "End of transmission block" ??
How would someone type one of these?
ASCII 05 is Ctrl+E and ASCII 23 is Ctrl+W as seen from http://nemesis.lonestar.org/referenc...des/ascii.html.
I would like to find a more elegant way to do this rather than manually defining each block like this : - if (e.KeyData == (Keys.Control | Keys.A))
-
{
-
test = (char)01;
-
-
-
}
-
-
if (e.KeyData == (Keys.Control | Keys.B))
-
{
-
test = (char)02;
-
-
-
}
-
-
-
if (e.KeyData == (Keys.Control | Keys.C))
-
{
-
test = (char)03;
-
-
-
}
-
How do you feel about this logic? (suedo code, you can flush out)
On keypress
if control key pressed
{
switch e.KeyData
{
Case E
...
Case W
...
Case R
...
}
else
{
// No control key so we don't care
}
}
Out of curiosity, do you need this globally (from outside the application), or just inside the particular control?
Not exactly what I was looking for. I would prefer grabbing the KeyCode of the keypress and then putting it in a char.
@GaryTexmo
Just inside the particular control (textbox).
I tried a google search and came up with this... http://www.java2s.com/Code/CSharp/Ev...Keypressed.htm
You don't need to worry about the ASync method in there. The particular lines of code that should interest you are... - lbl.Text = "Key Down: " + e.KeyValue.ToString();
-
lbl.Text += "\nKey Code: " + e.KeyCode.ToString();
-
lbl.Text += "\nKey Data: " + e.KeyData.ToString();
... which would be in your KeyDown event.
Does that help any?
@GaryTexmo
Not exactly, I already know about key modifiers, codes , values and such. The challenge is simplifying my existing code and enhancing it to include all keyboard modifiers.
Like what? I tried that little demo program on the site and it was trapping ctrl-e, which is one of the things you wanted.
Oooh, you mean you want the actual ascii value of it? I see... well that changes everything :D Sorry for the confusion.
I'm at a loss here. I tried a few console programs in C# and QBasic and I was able to get the functionality you want by reading the input stream, but I can't figure out how to do it on a form. I even tried some code I had that would read a global input stream that used all sorts of dllimports thinking maybe there was something in there, but it returns the same as the event arguments.
At this point, I think I agree with Thlintoq's method. While it's not exactly what you wanted, it will give you what you're looking for.
It looks like the KeyValue of the event is the Ascii value of the key (in uppercase), thus the following works: -
if (e.Modifiers == Keys.Control && e.KeyValue >='A' && e.KeyValue <='Z')
-
int test = e.KeyValue - 'A' + 1;
-
Be aware that this relies on undefined behaviour as it's never specified what the KeyValue of a specific key is.
Edit:
To make it a bit safer, you could have: -
int test = e.KeyValue - (int)Keys.A + 1;
-
That's guaranted to work as long as the values of Keys.A to Keys.Z are all consecutive and in the right order in the Keys enum.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pratap Das |
last post by:
Hi All,
I am writing sort of a shell in Perl where I am trying to implement
command recall at shell prompt like you have for zsh/tcsh. So when I
press up/down arrow keys I should be able to get...
|
by: wob |
last post by:
Many thanks for those who responded to my question of "putting greek char
into C string". In searching for an solution, I noticed that there are more
than one version of "Extended ASCII...
|
by: Kai Bohli |
last post by:
Hi all !
I need to translate a string to Ascii and return a string again. The code below dosen't work for
Ascii (Superset) codes above 127. Any help are greatly appreciated.
protected...
|
by: Ger |
last post by:
I have not been able to find a simple, straight forward Unicode to ASCII
string conversion function in VB.Net.
Is that because such a function does not exists or do I overlook it?
I found...
|
by: Z.K. |
last post by:
In C#, using the StreamReader, how do I detect when you get to the end
of line. I am reading a text file using the Read() function and I need
to detect the \n\r, but everything I try does not...
|
by: John |
last post by:
Hi,
I'm a beginner is using C# and .net.
I have big legacy files that stores various values (ints, bytes, strings) and want to read them into
a C# programme so that I can store them in a...
|
by: JohnLongHorn97 |
last post by:
Hello everyone,
I would like to write a script that will read several ascii characters directly into the STDIN, so it will be like I pressed these values in my keyboard, in another window.
for...
|
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= |
last post by:
Hello,
I have a KeyDown event in which I would like to determine if the current key
is a standard character (i.e., from the ASCII character set). In C I would
use something like the isascii...
|
by: Pilcrow |
last post by:
Is there a way that a proram can detect whether it is operating in an
ASCII or an EBCDIC environment?
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
|
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,...
| |