gpt4 book ai didi

IE10 中的 JavaScript 键盘事件

转载 作者:行者123 更新时间:2023-12-04 20:40:20 25 4
gpt4 key购买 nike

我一直在尝试获取 VBA 脚本来调度 keydown 事件但没有成功......
没有太多关于让“iniKeyboardEvent”在 InternetExplorer 上工作的信息。

Sub ie_evt()

Dim ie As InternetExplorer
Dim doc As HTMLDocument

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onkeydown.htm"
Do While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
ie.Visible = True

Set doc = ie.Document

doc.parentWindow.execScript ("var tb = document.getElementById('oExample')")
doc.parentWindow.execScript ("tb.value = 'a'")
doc.parentWindow.execScript ("var e = document.createEvent('KeyboardEvent')")
doc.parentWindow.execScript ("e.initKeyboardEvent('keydown', true, true, window, false, false, false, false, 65, 0);")
doc.parentWindow.execScript ("tb.dispatchEvent(e)")
End Sub

任何人都可以帮助我吗?

谢谢

最佳答案

这在 VBA 中充其量总是很狡猾,但您可以尝试使用 Win API 将键盘事件发送到事件窗口。 2个要点:

  • 确保 IE 窗口在发送按键事件时是事件窗口(您可以使用 AppActivate() 或其他 API 方法来执行此操作)
  • 您需要知道要“按”的键的虚拟键代码 here is a list of most of them

  • 然后在标准代码模块中是这样的:
    #If Win64 Then
    Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    #Else
    Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    #End If

    '// Example, send the number 5
    Const NUM_5 As Byte = &H65

    Sub foo()

    '// your code here - ensure IE window is active window and then:

    '// Send key press event
    keybd_event NUM_5, 0&, 0&, 0&

    '// rest of code
    End Sub

    关于IE10 中的 JavaScript 键盘事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35006026/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com