Can automatic press backspace when scanning barcodes in the textbox on the vb.net?
is there any other solution or my code is wrong?
Thanks
Private Sub txtUser_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtUser.KeyPress
Const pattern As String = "USERNAME : (\S+)-PASSWORD : (\S+)"
If e.KeyChar = ChrW(8) Then
Dim m As Match = Regex.Match(txtUser.Text, pattern)
If m.Success Then
e.KeyChar = ControlChars.Back
txtUser.Text = m.Groups(1).Value
txtPassword.Text = m.Groups(2).Value
Else
'TODO: display some message
End If
End If
End Sub
Result scanner after press backspace in keyboard.
so I want immediate results without pressing backspace on the keyboard as below


The barcode scanners add an enter at the end of the text. You can handle the keydown event instead of keypress to detect when Enter key is pressed and do something like that:
With this code, you don't need to press the backspace key to split the barcode input into the two fields.
I hope that is helpful.