Visual Basic中SendKeys()权限被拒绝错误

Pho*_*hox 11 vb6 sendkeys

我试图SendKeys()用我的VB6应用程序将命令用于另一个窗口.

我想要的是单击一个按钮,然后在应用程序向该窗口发送一些键之前有10秒钟转到另一个窗口.我把所有东西都排序了,但出于某种原因我打电话的时候是这样的:

SendKeys ("A")
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Run-time error '70':

Permission denied
Run Code Online (Sandbox Code Playgroud)

有没有人知道这方面的方法?谢谢.

小智 9

对于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 
Run Code Online (Sandbox Code Playgroud)

它在Windows 10中对我很好.


Jim*_*ack 8

看看Karl Peterson在Vista下解决这个问题的方法:

SendInput


Rom*_*hke 6

VB6 SendKeys 的替代品是 WScript.Shell SendKeys,如下所示:

Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "1{+}"
Run Code Online (Sandbox Code Playgroud)

请参阅MSDN获取帮助。


rub*_*low 6

在公共模块中添加:

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
Run Code Online (Sandbox Code Playgroud)

这将“覆盖”SendKeys 函数