Как средствами VB6 (API, sendmessage, и пр.) вставить некий текст в окно редактирования или контрол текущего приложения (word, notepad, IE,..), находящийся в фокусе ввода?
Спасибо.
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetForegroundWindow& Lib "user32" ()
Public Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
Public Declare Function ActivateKeyboardLayout Lib "user32" (ByVal HKL As Long, ByVal flags As Long) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Const WM_CHAR = &H102
Public Const WM_INPUTLANGCHANGEREQUEST = &H50
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 Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub kb1(ByRef l1 As String, ByRef lang1 As String)
If Len(l1) = 0 Then Exit Sub
Dim l101, hwin, lCodeKeybord As Long
Dim forto_kb As Long
Dim vk_kb As Long
hwin = FindWindow(класс окна, "Заголовок окна")
или hwin =GetForegroundWindow&()
If lang1 = "ru" Then
lCodeKeybord = GetKeyboardLayout(GetWindowThreadProcessId&(GetForegroundWindow&, 0&))
If lCodeKeybord <> 68748313 Then
PostMessage hwin, WM_INPUTLANGCHANGEREQUEST, 0, 68748313
ActivateKeyboardLayout 68748313, 0
Sleep 100
end if
End If
If lang1 = "en" Then
lCodeKeybord = GetKeyboardLayout(GetWindowThreadProcessId&(GetForegroundWindow&, 0&))
If lCodeKeybord <> 67699721 Then
PostMessage hwin, WM_INPUTLANGCHANGEREQUEST, 0, 67699721
ActivateKeyboardLayout 67699721, 0
Sleep 100
end if
End If
l101 = Len(l1)
For forto_kb = 1 To l101
vk_kb = Asc(Mid(l1, forto_kb, 1))
PostMessage hwin, WM_CHAR, vk_kb, &H100001
Sleep 50
Next
End Sub
Сейчас этот форум просматривают: AhrefsBot, Yandex-бот и гости: 50