-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteclado.bas
More file actions
141 lines (120 loc) · 4.92 KB
/
Copy pathteclado.bas
File metadata and controls
141 lines (120 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
Attribute VB_Name = "teclado"
Option Explicit
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public 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
Public Const WM_LBUTTONDOWN As Long = &H201
Public Const WM_LBUTTONUP As Long = &H202
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2
Public Const GW_CHILD = 5
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE
Public Const WM_SETTEXT = &HC
Private Const WM_KEYDOWN = &H100
Private Const VK_RETURN = &HD
' Function Keys
'Private Const VK_F1 = &H70
'Private Const VK_F2 = &H71
'Private Const VK_F3 = &H72
'Private Const VK_F4 = &H73
'Private Const VK_F5 = &H74
'Private Const VK_F6 = &H75
'Private Const VK_F7 = &H76
'Private Const VK_F8 = &H77
'Private Const VK_F9 = &H78
'Private Const VK_F10 = &H79
'Private Const VK_F11 = &H7A
'Private Const VK_F12 = &H7B
Public Enum TeclaFuncao
VK_F1 = &H70
VK_F2 = &H71
VK_F3 = &H72
VK_F4 = &H73
VK_F5 = &H74
VK_F6 = &H75
VK_F7 = &H76
VK_F8 = &H77
VK_F9 = &H78
VK_F10 = &H79
VK_F11 = &H7A
VK_F12 = &H7B
End Enum
Public Function WindowClass(ByVal hwnd As Long) As String
Const MAX_LEN As Byte = 255
Dim strBuff As String, intLen As Integer
strBuff = String(MAX_LEN, vbNullChar)
intLen = GetClassName(hwnd, strBuff, MAX_LEN)
WindowClass = Left(strBuff, intLen)
End Function
Public Function WindowTextGet(ByVal hwnd As Long) As String
Dim strBuff As String, lngLen As Long
lngLen = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0)
If lngLen > 0 Then
lngLen = lngLen + 1
strBuff = String(lngLen, vbNullChar)
lngLen = SendMessage(hwnd, WM_GETTEXT, lngLen, ByVal strBuff)
WindowTextGet = Left(strBuff, lngLen)
End If
End Function
Public Function WindowTextSet(ByVal hwnd As Long, ByVal strText As String) As Boolean
WindowTextSet = (SendMessage(hwnd, WM_SETTEXT, Len(strText), ByVal strText) <> 0)
End Function
Public Sub clica_externo(Janela As String, Botao As String)
Dim lngHandle As Long, lngHandlePai As Long
Debug.Print "Dialogo:" + Janela + "-" + Botao
lngHandlePai = FindWindow(vbNullString, Janela)
If lngHandlePai > 0 Then
lngHandle = achaFilho(lngHandlePai, Botao)
If lngHandle > 0 Then
Call ClickButton3(lngHandle)
End If
End If
End Sub
Public Function achaFilho(ByVal lngHandlePai As Long, nomeFilho As String) As Long
Dim lngHandleNeto As Long, lngHandleFilho As Long, texto As String, resultFilho As Long
lngHandleFilho = GetWindow(lngHandlePai, GW_CHILD)
Do Until lngHandleFilho = 0
'Testa o iten filho
texto = WindowTextGet(lngHandleFilho)
Debug.Print "classe:" & WindowClass(lngHandleFilho) & " Valor:" & texto
If texto = nomeFilho Then
achaFilho = lngHandleFilho
Exit Function
Else
resultFilho = achaFilho(lngHandleFilho, nomeFilho)
If resultFilho <> 0 Then
achaFilho = resultFilho
Exit Function
End If
End If
lngHandleFilho = GetWindow(lngHandleFilho, GW_HWNDNEXT)
Loop
achaFilho = 0
End Function
Public Sub ClickButton3(ByVal hWndChild As Long)
Dim lResult As Long
lResult = PostMessage(hWndChild, WM_LBUTTONDOWN, 1, 0)
Debug.Print lResult
lResult = PostMessage(hWndChild, WM_LBUTTONUP, 1, 0)
Debug.Print lResult
End Sub
Public Sub EnviarTecla(ByVal lngHandlePai As Long, Tecla As TeclaFuncao)
If lngHandlePai > 0 Then
Call PostMessage(lngHandlePai, WM_KEYDOWN, Tecla, 0)
End If
End Sub
Public Function AcharJanela(Janela As String) As Long
Dim lngHandlePai As Long, classe As String
lngHandlePai = FindWindow(vbNullString, Janela)
classe = WindowClass(lngHandlePai)
Debug.Print "Dialogo:" + Janela + "(" & classe & ")-Enter"
If classe = "MozillaDialogClass" Then
lngHandlePai = GetWindow(lngHandlePai, GW_CHILD)
End If
AcharJanela = lngHandlePai
End Function