Keyboard hooks and key resolution
Ok, now that I can capture the keystrokes for the UPC program, I have an issue with getting the numpad numbers.
How can get thevkCode to convert correctly and it not matter where it came from? I can use Chr to get the home numbers, but the numpad pulls back different codes and Chr brings back lower-case versions of letters.
I rather not use a select structure to accomplish this either.
Code:
Private Sub kbHook_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles kbHook.KeyPress
Dim upc As String
'The enter/ctrl key was press so we need to check if it has the right data
If Asc(e.KeyChar) = Keys.Enter Or Asc(e.KeyChar) = Keys.LControlKey Or Asc(e.KeyChar) = Keys.RControlKey Then
'If the length of the string is >= to the specified length
'process it and the clear the array for the next keystrokes
If (upcInput2.ToString.Length >= config.UPCLength) Then
upc = Me.ParseUPC(upcInput2.ToString.Substring(0, config.UPCLength))
WebBrowser1.Navigate(config.BaseURL & upc)
sLabelUPC.Text = upc
Me.upcHistory.AddItem(Now, slblUser.Text, upc)
upcInput2.Remove(0, upcInput2.Length)
Else
'The enter key was pressed but we didn't have enough characters for a UPC
'remove all characters and start over.
upcInput2.Remove(0, upcInput2.Length)
End If
Else
'We are looking for a UPC, if the character isn't numeric, we don't care about it
'and should clear the array
If IsNumeric(e.KeyChar) Then
upcInput2.Append(e.KeyChar)
Else
upcInput2.Remove(0, upcInput2.Length)
End If
End If
End Sub