I have a handler for the TextBox's PreviewLostKeyboardFocus
event. It fires when I leave the TextBox using the keyboard (Tab key) or the mouse (by clicking on another TextBox on the form).
The handler takes a KeyboardFocusChangedEventArgs
, which has a property named KeyboardDevice
, which isn't null in either scenario (I was hoping to find null
here when using the mouse).
Question: How can I tell whether a user used the keyboard or the mouse to leave a WPF TextBox?
The e.KeyboardDevice.GetKeyStates(Key.Tab) (where e is of type KeyboardFocusChangedEventArgs) reports:
Would that work for you?
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