Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mixed input source for textbox 1

Status
Not open for further replies.

oscarse

Programmer
Apr 9, 2006
99
CA
I used a textbox set up with fixed focus to accept input from either a USB BarcodeReader or a Numeric KeyPad ... this has worked well using a combination of the timer function to maintain focus on the textbox, and a KeyPress Event to monitor "{backspace}", "Del (.)", and "{Enter}". Basically a Barcode Reader will scan in a number followed by an enter ... enter takes the number and clears the text box for the next entry ... the numeric keypad works the same way ... the timer continually watches to make sure the textbox is always in focus.

Now I have been asked to also include an onscreen Keypad that can be triggered by mouse clicks (so we can eliminate the numeric pad) ... I expected all I would need to do is use the SENDKEYS function and just use the existing events but have run into a number of issues;

Private Sub btn<number>_Click()
Call SimKey("<number>")
End Sub

Private Sub SimKey(strKey As String)
Debug.Print strKey

Me!txtBarCodeReader.Setfocus
sendkey strKey, wait

End Sub

In this case the Sendkeys key is not being handled by the textbox in an expected way ... it only enters one character (the last one entered) ... by clicking on a button I gather because the textbox has lost focus it resets itself which then sets it to overwrite on the next entry ... so what I attempted to do to counter this by concating the keys with the following variation

Private Sub SimKey(strKey As String)
Debug.Print strKey
Me!txtBarCodeReader.SETFOCUS
If Len(strKey) = 1 Then '0-9
Me!txtBarCodeReader.Text = Me!txtBarCodeReader.Value & strKey
ElseIf strKey = "{Backspace}" Then
If Len(Me!txtBarCodeReader.Value) > 0 Then
Me!txtBarCodeReader.Text = Mid(Me!txtBarCodeReader.Value, 1, Len(Me!txtBarCodeReader.Value) - 1)
End If
Else 'Simulates {Enter}
SendKeys strKey, False
End If
End Sub


This is also not a great solution as the cursor is always left adjusted which causes an issue if we still want to enter data from a remote connection via a keyboard. The other issue is the keyboard Backspace is no longer working.

Does anyone have another way to simulate a keyboard onscreen and still maintain the existing functionality and or be able to have the TEXTBOX always APPEND?
 
have the TEXTBOX always APPEND
You may try something like this in the GotFocus event procedure of txtBarCodeReader:
Me!txtBarCodeReader.SelStart = 1 + Len(.Text)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Have you considered suspending the operation of the timer when entering via the on-screen keyboard?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top