有鍵盤和USB條形碼閱讀器來區分的方式
你可以依靠這些事實:
- 通過條碼閱讀器在minmum 4個字符掃描碼
- 通過掃描QR碼條碼閱讀器以RETURN「ENTER」結尾
- 掃描孔條碼需要不到50毫秒的時間
這是使用VS2005 VB一個簡單的形式包含:
- TextBox1中
- TextBox2中
- textbox3
- Button1的
- 定時器1 「的時間間隔設置爲50」 MS」
Public Class Form1
Dim BarcodeStr As String = ""
Dim IsBarcodeTaken As Boolean = False
Dim Str As String = ""
Dim str3 As String = ""
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If Timer1.Enabled = False Then
Str = TextBox1.Text
str3 = TextBox3.Text
End If
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If Timer1.Enabled = False Then
Timer1.Enabled = True
End If
BarcodeStr = BarcodeStr & e.KeyChar
If Asc(e.KeyChar) = 13 And Len(BarcodeStr) >= 4 Then
IsBarcodeTaken = True
TextBox2.Text = BarcodeStr
End If
End Sub
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If IsBarcodeTaken = True Then
TextBox1.Text = Str
TextBox1.Select(Len(TextBox1.Text), 0)
Str = ""
TextBox3.Text = str3
TextBox3.Select(Len(TextBox3.Text), 0)
str3 = ""
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
BarcodeStr = ""
IsBarcodeTaken = False
Timer1.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = ""
End Sub
End Class
由於我沒有足夠的代表來編輯其他人的帖子,請讓我爲你翻譯:「假設掃描儀至少輸入4個字符,以ENTER鍵結束,並採用50ms以下的操作。」這聽起來對我來說是個好主意,但也許你應該讓時間爲100ms。 – MiffTheFox 2009-06-18 12:03:16
恐怕,這是不正確的。您可以**通過使用[原始輸入](https://msdn.microsoft.com/en-us/library/windows/desktop/ms645536.aspx)告訴哪個設備生成輸入。您不需要知道VID和PID,因爲USB掃描儀具有指定的* UsagePage *和* Usage *條目。 – IInspectable 2017-01-09 16:21:00