SendKeys.send 正在发送密钥,但应用程序未将此密钥解释为命令

SendKeys.send is sending a key, but the application is not interpreting this key as a command

我正在使用 SendKeys 将击键发送到程序。

这是我的代码:

   If whandle <> 0 Then
        User32.SetForegroundWindow(whandle)
        System.Windows.Forms.SendKeys.Send("+")
    End If

(我也试过 SendWait() 而不是 Send()

这是我的 window Spy++ 显示的层次结构:

虽然我可以通过标题找到 window 句柄并使用 User32.FindWindowEx 遍历子句,但在调试时我只是输入 window 句柄,如 spy++ 所示(从十六进制转换为十进制)我发现:

所以我想我遇到了以下问题之一:

  1. 我在 windows 和 subwindows 上做错了(我真的不认为这会发生,因为我尝试了 Spy++ 显示的所有句柄)。
  2. SendKey("+") 与在 window 激活时按“+”键不完全相同,存在一些差异。

调用 User32.SetForegroundWindow(whandle) 后,如果我真的按下“+”键,就会出现所需的效果,即放大,但当我的程序执行 SendKeys 时不会。我还尝试了其他产生命令的键,比如 Q 或 A(它们都是简单的键和字母)。

来自MS Docs

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use "{+}"

System.Windows.Forms.SendKeys.Send("{+}")