con sendkeys, funciona, pero no es estable al 100%
con sendmessage, no puedo lograrlo....
en realidad, puedo enviar sin foco, pero el vm_paste no.....
adjunto codigo, a ver si se ve el error... gracias
Código:
Private Declare Function FindWindowX Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, ByVal lpsz1 As Long, ByVal lpsz2 As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function BringWindowToTop Lib "user32" (ByVal hWnd As Long) As Long
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
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Integer) As Long
Private Const WM_PASTE = &H302
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Sub Three()
hWind = FindWindow(vbNullString, "Calculadora")
cWind = FindWindowX(hWind, 0, 0, 0)
Debug.Print PostMessage(cWind, WM_KEYDOWN, vbKey1, 0)
Debug.Print PostMessage(cWind, WM_KEYDOWN, vbKey2, 0)
Debug.Print PostMessage(cWind, WM_KEYDOWN, vbKey3, 0)
End Sub
Private Sub Command1_Click()
Three
End Sub
Sub Three2()
hWind = FindWindow(vbNullString, "Calculadora")
cWind = FindWindowX(hWind, 0, 0, 0)
Debug.Print PostMessage(cWind, WM_KEYDOWN, vbKey1, 0)
Debug.Print PostMessage(cWind, WM_KEYDOWN, vbKey2, 0)
Debug.Print PostMessage(cWind, WM_KEYDOWN, vbKey3, 0)
End Sub
Private Sub Command2_Click()
Three2
End Sub
Private Sub Command3_Click()
lnghwnd = FindWindow(vbNullString, "Calculadora")
Debug.Print lnghwnd
BringWindowToTop lnghwnd
ShowWindow lnghwnd, 1
'strProv = "Esta es una prueba"
'For i = 1 To Len(strProv)
'keybd_event Asc(Mid(strProv, i, 1)), 0, 0, 0
'keybd_event Asc(Mid(strProv, i, 1)), 0, KEYEVENTF_KEYUP, 0
'Next i
'keybd_event 13, 0, 0, 0
'keybd_event 13, 0, KEYEVENTF_KEYUP, 0
If lnghwnd <> 0 Then
SendKeys ("123")
SendKeys ("{+}")
SendKeys ("456")
SendKeys ("{enter}")
'Timer2.Enabled = True
'Me.WindowState = 1
Exit Sub
End If
End Sub
Private Function FromClip(hWnd As Long)
SendMessage hWnd, WM_PASTE, 0, 0
End Function
Private Sub Command4_Click()
lnghwnd = FindWindow(vbNullString, "Calculadora")
Debug.Print lnghwnd
BringWindowToTop lnghwnd
ShowWindow lnghwnd, 1
'strProv = "Esta es una prueba"
'For i = 1 To Len(strProv)
'keybd_event Asc(Mid(strProv, i, 1)), 0, 0, 0
'keybd_event Asc(Mid(strProv, i, 1)), 0, KEYEVENTF_KEYUP, 0
'Next i
'keybd_event 13, 0, 0, 0
'keybd_event 13, 0, KEYEVENTF_KEYUP, 0
If lnghwnd <> 0 Then
FromClip (lnghwnd)
'SendKeys ("123")
'SendKeys ("{+}")
'SendKeys ("456")
'SendKeys ("{enter}")
'Timer2.Enabled = True
'Me.WindowState = 1
Exit Sub
End If
End Sub
dejo los comentarios porque eran ideas, que fui cambiando... gracias
ps: el command4 es el que da lios....