Findwindow 和 SendMessage [英] Findwindow and SendMessage

查看:20
本文介绍了Findwindow 和 SendMessage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚为什么这不向记事本发送 ALT+F,

I am trying to figure out why this is not sending a ALT+F to notepad,

Private Declare Function FindWindow1 Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_KEYUP = &H101
Private Const WM_KEYDOWN = &H100
Private Const WM_SYSKEYDOWN = &H104

Private Sub Command_Click()
Dim parenthwnd As Long
Dim hwnd As Long

  parenthwnd = FindWindow1(vbNullString, "Untitled - Notepad")
  retvalue = SendMessage(parenthwnd, WM_SYSKEYDOWN, VK_MENU, 1&)
  retvalue = SendMessage(parenthwnd, WM_KEYDOWN, VK_F, 1&)
End Sub

我得到了 parenthwnd 的值,但没有得到任何 retvalue 值 (0).

I get a value for parenthwnd but not for any of the retvalue values (0).

我错过了什么?

推荐答案

您可以尝试随心所欲地发送/发布这些消息.不幸的是,它们不会影响 GetAsyncKeyState 的返回值 - 这是系统在处理 VK_F 消息时使用的 - 以查看 alt 是否已关闭.

You can try to send/post these messages all you want. Unfortunately they don't effect the return value of GetAsyncKeyState - which is what the system uses, while processing the VK_F message - to see if the alt is down.

因此,您无法使用此机制将带有修饰符的击键伪装成其他应用程序.

As a result you can't fake keystrokes with modifiers to other applications using this mechanism.

要解决此问题,您需要使用 SendInput - 但这要求接收击键的应用程序是前景/焦点窗口.

To get around this, you need to use SendInput - but this requires that the application to receive the keystrokes is the foreground/focus window.

这篇关于Findwindow 和 SendMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆