i want to recognize keystrokes to my Control. For this i use the KeyDown Event. The Kind of keystrokes I want to detect are something like CTRL + A or CTRL + C and so on. (So combinations of multiple keys)
Now I have revied the KeyEventArgs and found the Keys enum. (Everything works perfect just use | and & to Combine and find the correct keys) An Example could be Shift + A then the Value of the KeyData Enum is: ShiftKey | Shift | A
BUT
When i try it with the Control Key pressed (so Control + A) i got 131137 as Response? And I do not know exactly why I do not get something like ControlKey | Control | A (or something like this)
I have recogniced if I try it with A ist 131137 with B ist 131138 with C ist 131139 and so on ... So I think it is possible to calculate the key but I think there should be a better solution then just so something like this?
131137 - 131072 = 65 (for A)
Am I right, or is this the prevered solution, or do I misunderstand some Basic?
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
You can get Ctrl, Shift etc... using properties in KeyEventArgs object
http://msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs_properties(v=vs.90).aspx
void Control_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.F4)
{
// Be happy
}
}
131072 == (int) Keys.Control
so
131137 (100000000001000001 binary) == (int) (Keys.Control | Keys.A)
and you can put something like that
private void myControl_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyData == (Keys.A | Keys.Control)) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With