Findwindow and SendMessage

笑着哭i 提交于 2019-12-02 04:03:56

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.

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

I think this is the problem: you're sending your message to the frame around the notepad window, and need to send it to the menu window. Use your handle with FindWindowEx and the 32768 class name (that's a menu) to get the menu window, which is a child of the one you've got the handle to. Here are two pages: http://msdn.microsoft.com/en-us/library/ms633500(v=VS.85).aspx and http://msdn.microsoft.com/en-us/library/ms633574(VS.85).aspx#class_name that should help.

Cidtek

Use Postmessage instead of Sendmessage

Public Const WM_SYSKEYDOWN = &H104

PostMessage hwnd, WM_SYSKEYDOWN, vbKeyF, 2 ^ 29 

'Simulates Alt + F (2^29 sets the 29 bit of lParam indicating Alt is being pressed.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!