I have a handle for a currency value. It should allow negative value say -555.
On keydown/Keypress, when I try to find the Key value for Subtract key in Numpad, it gives me as Key.Subtract in IE versions. But in chrome/firefox latest versions, it shows me as Key.Unknown.
Is there any specific handle needs to be done.
Sample:
if ((e.Key >= Key.D0 && e.Key <= Key.D9) || (e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) || (e.Key == Key.Subtract) || (e.Key == Key.Unknown))
{
//valid number, but if shift is pressed, it is an invalied character
if (Keyboard.Modifiers == ModifierKeys.Shift)
e.Handled = true;
}
else
e.Handled = true;
Here, I have handled the unknown key explicitly. But is there any standard way to get rid of this? Please help me.
I have run into the same problem when some customers do not use IE. What you have to do is you have to check the value of PlatformKeyCode which has difference value on difference OS, for example, PlatformKeyCode of . is 190 on a Windows but it is 47 on Mac.
Below statement quoted from KeyEventArgs.PlatformKeyCode Property on MSDN.
On my machine the PlatformKeyCode value of - is 189.