Other Software > Developer's Corner
Distinguish Enter and Numpad Enter Key c#.net
(1/1)
stophereareyou:
Hello Every one,
Is there any way to distinguish Numpad Enter key and Normal Enter Key,
in c#.net<code> KeyCode, KeyCode</code> and <code>KeyValue</code> for both keys are same,
is there any other way or some workaround for distinguishing Events raised by both keys?!
Firdaus Shaikh
('',)
wraith808:
Though the Keys enum has identical values for Enter and Return (it also has a number of other duplicates), ToString shows a different value.
If you run this linq expression in linqpad, you'll see what I mean.
--- Code: C# ---Enum.GetNames(typeof(System.Windows.Forms.Keys)) .GroupBy(k => Enum.Parse(typeof(System.Windows.Forms.Keys), k)) .Where(g => g.Count() > 1) .Select(g => String.Join(", ", g.Select(k => k.ToString()).ToArray())).Dump();
Check for the tostring if you really need to know the difference.
stophereareyou:
Though the Keys enum has identical values for Enter and Return (it also has a number of other duplicates), ToString shows a different value.
If you run this linq expression in linqpad, you'll see what I mean.
--- Code: C# ---Enum.GetNames(typeof(System.Windows.Forms.Keys)) .GroupBy(k => Enum.Parse(typeof(System.Windows.Forms.Keys), k)) .Where(g => g.Count() > 1) .Select(g => String.Join(", ", g.Select(k => k.ToString()).ToArray())).Dump();
Check for the tostring if you really need to know the difference.
-wraith808 (March 16, 2013, 04:37 PM)
--- End quote ---
Hello wraith808,
I did not understand all of it but,
Tried it in C# as follows
--- ---
foreach (var VARIABLE in Enum.GetNames(typeof (System.Windows.Forms.Keys))
.GroupBy(k => Enum.Parse(typeof (System.Windows.Forms.Keys), k))
.Where(g => g.Count() > 1)
.Select(g => String.Join(", ", g.Select(k => k.ToString()).ToArray())))
{
richTextBox1.AppendText(VARIABLE+"\r\n");
}
Got following...
--- ---Enter, Return
CapsLock, Capital
HangulMode, HanguelMode, KanaMode
KanjiMode, HanjaMode
IMEAccept, IMEAceept
Prior, PageUp
PageDown, Next
Snapshot, PrintScreen
OemSemicolon, Oem1
Oem2, OemQuestion
Oem3, Oemtilde
Oem4, OemOpenBrackets
OemPipe, Oem5
OemCloseBrackets, Oem6
OemQuotes, Oem7
Oem102, OemBackslash
that is Enter and Return does have same value,
Thanks for your time and code, I might have missed your point if you are telling something more than I've understood,
but is there any difference between Main Enter Key and Enter Key on Numpad!?
Firdaus Shaikh
('',)
wraith808:
Enter and Return don't have the same value if you check the tostring.
for example:
--- Code: C# ---switch (keyVariable.ToString()){ case "Enter": // they pressed the numpad enter key Console.WriteLine("Numpad Enter Key"); break; case "Return": // they pressed the keyboard enter key Console.WriteLine("Keyboard Enter Key"); break;}
Don't take my word on which is which... I didn't check. But the strings are different, so you can check for them is the point.
Navigation
[0] Message Index
Go to full version