14

我正在尝试SendKeys()通过我的 VB6 应用程序将该命令用于另一个窗口。

我想要的是单击一个按钮,然后在应用程序向该窗口发送一些键之前有 10 秒的时间转到另一个窗口。我把所有东西都整理好了,但出于某种原因,当我这样称呼时:

SendKeys ("A")

我收到此错误:

Run-time error '70':

Permission denied

有谁知道解决这个问题的方法?谢谢。

4

9 回答 9

19

对于 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 中对我来说效果很好。

于 2016-04-23T01:56:55.157 回答
8

看看 Karl Peterson 在 Vista 下如何解决这个问题:

发送输入

于 2010-02-22T03:16:07.593 回答
6

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

Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "1{+}"

请参阅MSDN以获得帮助。

于 2014-11-12T15:08:43.217 回答
5

在公共模块中添加:

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 函数

于 2015-10-11T00:26:07.760 回答
4

On Windows 7:

  • Open the Control Panel
  • Change user account control setting
  • Change to NEVER NOTIFY
  • Restart the computer
于 2010-07-10T14:32:53.897 回答
2

从应用程序中删除“msvbvm60.dll”文件

按照以下步骤

  1. 右键单击应用程序 .exe 文件并单击属性
  2. 单击兼容性选项卡
  3. 单击以兼容模式运行此程序并从中选择 Windows Xp SP2。
  4. 单击以管理员身份运行此程序
  5. 单击应用比确定。
  6. 从应用程序文件夹中删除“msvbvm60.dll”。

全部完成,现在您的应用程序开始运行,没有任何错误,例如访问被拒绝

于 2014-05-12T06:55:48.433 回答
1

问题在于 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

于 2014-06-28T03:34:03.507 回答
1

您可以在模块中使用此代码

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
于 2015-05-12T07:50:02.630 回答
1

使用此 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 等时。

于 2015-08-17T17:51:21.143 回答