See link , example impl. below.
private static bool IsNumpadEnterKey(KeyEventArgs e) { if (e.Key != Key.Enter) return false; // To understand the following UGLY implementation please check this MSDN link. Suggested workaround to differentiate between the Return key and Enter key. // https://social.msdn.microsoft.com/Forums/vstudio/en-US/b59e38f1-38a1-4da9-97ab-c9a648e60af5/whats-the-difference-between-keyenter-and-keyreturn?forum=wpf try { return (bool)typeof(KeyEventArgs).InvokeMember("IsExtendedKey", BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Instance, null, e, null); } catch (Exception ex) { if (AiLoggingService.IsErrorEnabled) AiLoggingService.LogError("Could not get the internal IsExtendedKey property from KeyEventArgs. Unable to detect numpad keypresses.", ex); } return false; }
Nb if you want to check the regular EnterKey, then obviously you should call
e.Key == Key.Enter && !IsNumpadEnterKey(e)
source share