Using sendkeys to send text instability sometimes garbled

text1.text="a17"
SendKeys frmMain.Text1.Text

How to display in the other window sometimes is "a! &, sometimes show;""a17"

Started by Hyman at December 22, 2016 - 9:43 AM

Option Explicit
Private Const WM_CHAR = &H102
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'A string is sent by PostMessage
Private Sub subPostString(ByVal lngHandle As Long, ByVal strP As String)
Dim intP As Integer
Dim intK As Integer
Dim lngAsc As Long
Dim lngP As Long
Dim strT As String
On Error GoTo errSub
For intP = 0 To Len(strP) - 1
strT = Mid(strP, intP + 1, 1)
If Asc(strT) <= 0 Then
lngAsc = AscW(StrConv(strT, 128))
If lngAsc <0 Then
lngAsc = lngAsc + 65536 '2^16
End If
Else
lngAsc = Asc(strT)
End If
lngP = PostMessage(lngHandle, WM_CHAR, lngAsc, 0)
Next intP
Exit Sub
errSub:

End Sub
Private Sub Command1_Click()
Call subPostString(Text1.hwnd, "a17") 'Sends a string to the input text box
End Sub

Posted by Norton at January 02, 2017 - 10:04 AM

Perhaps you do not care at the same time, press the shift key.!

Posted by Drew at January 08, 2017 - 10:50 AM