How to determine if selection is made programmatically or by user input.
I started to write something but since there is more work I decided to seek for some out-the-box procedure or rely on the community experience.
So here is what I wrote (Note that answers in C# are welcommed too):
Private Shared Function IsUserSelect() As Boolean
If Mouse.LeftButton = MouseButtonState.Pressed Then Return True
Dim shift As Boolean
shift = Keyboard.IsKeyDown(Key.LeftShift)
If Not shift Then shift = Keyboard.IsKeyDown(Key.RightShift)
If shift Then
Dim arrow As Boolean
arrow = Keyboard.IsKeyDown(Key.Right)
If Not arrow Then arrow = Keyboard.IsKeyDown(Key.Left)
If arrow Then Return True
End If
Return False
End Function
To be called at the OnSelectionChanged of a TextBox and determine if the selection is made by user or virtually.
But then I realize that there are way more options: Shift+Home, Shift+PageDown and more.
I would rather trust a tested function then reinventing the puncture wheel.
Thanks for reading.