我正在尝试SendKeys()
通过我的 VB6 应用程序将该命令用于另一个窗口。
我想要的是单击一个按钮,然后在应用程序向该窗口发送一些键之前有 10 秒的时间转到另一个窗口。我把所有东西都整理好了,但出于某种原因,当我这样称呼时:
SendKeys ("A")
我收到此错误:
Run-time error '70':
Permission denied
有谁知道解决这个问题的方法?谢谢。
对于 Windows 7: 将 UAC 设置更改为从不通知。
对于 Windows 8 和 10:
将此方法添加到任何模块:
Public Sub Sendkeys(text as variant, Optional wait As Boolean = False)
Dim WshShell As Object
Set WshShell = CreateObject("wscript.shell")
WshShell.Sendkeys cstr(text), wait
Set WshShell = Nothing
End Sub
它在 Windows 10 中对我来说效果很好。
看看 Karl Peterson 在 Vista 下如何解决这个问题:
VB6 SendKeys 的替代品是 WScript.Shell SendKeys,如下所示:
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "1{+}"
请参阅MSDN以获得帮助。
在公共模块中添加:
Public Sub Sendkeys(text$, Optional wait As Boolean = False)
Dim WshShell As Object
Set WshShell = CreateObject("wscript.shell")
WshShell.Sendkeys text, wait
Set WshShell = Nothing
End Sub
这将“覆盖” SendKeys 函数
On Windows 7:
从应用程序中删除“msvbvm60.dll”文件
按照以下步骤
- 右键单击应用程序 .exe 文件并单击属性
- 单击兼容性选项卡
- 单击以兼容模式运行此程序并从中选择 Windows Xp SP2。
- 单击以管理员身份运行此程序
- 单击应用比确定。
- 从应用程序文件夹中删除“msvbvm60.dll”。
全部完成,现在您的应用程序开始运行,没有任何错误,例如访问被拒绝
问题在于 vb6 IDE 和 Windows 桌面上下文菜单,您将按照此处所述进行操作:
http://www.vbforums.com/showthread.php?747425-SendKeys-and-Windows-8
主要参考在这里:
http://www.vbforums.com/showthread.php?745925-RESOLVED-How-to-trigger-the-desktop-context-menu
您可以在模块中使用此代码
Public Sub SendKeyTab(CForm As Form)
On Error Resume Next
Dim G As Single
For G = 0 To CForm .Controls.Count - 1
If CForm .Controls(G).TabIndex = CForm .ActiveControl.TabIndex + 1 Then CForm .Controls(G).SetFocus
Next
End Sub
在每个表单级别
If KeyCode
使用此 API:
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
和
keybd_event keycode, 0, 0, 0 'KEY DOWN
keybd_event keycode, 0, KEYEVENTF_KEYUP, 0 'KEY UP
当键码为 32 表示空格、35 表示键端、8 表示 vbKeyBack 等时。