I have a function to detect a textfield to recognize a barcode scanner input or human input in my winform application:
DateTime lastKeyPress = DateTime.Now;
private void searchContent_TextChanged(object sender, EventArgs e)
{
TimeSpan elapsed = (DateTime.Now - lastKeyPress);
if (elapsed.TotalMilliseconds > 10)
{
cartBarcode.Text = "not barcode";
}
else
{
cartBarcode.Text = "is barcode";
//after the last character was printed
addBarcodeProductToCart ();
}
lastKeyPress = DateTime.Now;
}
private void addBarcodeProductToCart ()
{
cartGridView.Rows[0].Selected = true;
}
The problem of above is that after 2 characters was printed, addBarcodeProductToCart is already executed. How to detect last character was typed in above function?