When we use a keyboard which has two Enter-keys, and their keycode are both 13, how do we know which was pressed?
Asked
Active
Viewed 184 times
0
-
3To help you research one is actually the *return* key, the other the *enter* key. – Bathsheba Dec 15 '16 at 10:24
-
You would need to give us more information about your application for us to answer this. Techniques will vary between console, WPF, WinForms, asp.net applications. Some links here : http://stackoverflow.com/questions/11984238/detect-enter-key-c-sharp http://stackoverflow.com/questions/8898182/how-to-handle-key-press-event-in-console-application https://msdn.microsoft.com/en-us/library/ms752054(v=vs.110).aspx – PaulF Dec 15 '16 at 10:56
-
What @Bathsheba says is correct for the Macintosh and possibly other platforms, but Windows does *not* make a distinction between Enter and Return. The two keys are the same, and the Windows User Experience Guidelines explicitly state that the two keys should have identical command functionality. So, the answer to your question is, you don't! – Cody Gray - on strike Dec 15 '16 at 11:55
-
1Methinks you could still do some low level stuff with the keyboard scan codes: see https://en.wikipedia.org/wiki/Scancode – Bathsheba Dec 15 '16 at 12:19
-
@Bathsheba Thank you Sir,It's a C# application,Now my function is when I press the bigger Enter key then create a newline , and the Small one commit my request, – JEFF HO Dec 17 '16 at 02:45
-
public class KeyFilter : IMessageFilter { const int WM_KEYDOWN = 0x0100; const int VK_RETURN = 13; private Form parent; public bool PreFilterMessage(ref Message m) { switch (m.Msg) { case WM_KEYDOWN: if (VK_RETURN != ((int)m.WParam & 0xff)) return false; if (!(parent.ActiveControl is TextBox)) return false; if (((int)m.LParam & 0x1000000) != 0) { MessageBox.Show("小键盘回车"); } } – JEFF HO Dec 17 '16 at 02:49