I want to create an app that can send a message to the skype window saying that i pressed button x.(just an example)
How would I do that? I heard about spy++ but I have a hard time finding how to actually use it in code.
Jump to content
Posted 07 May 2013 - 08:15 AM
1) as prep work, call WindowFromPoint() to manually get the Skype window's name by hovering over it on your desktop (or just google for it ;) ) - just call it as response to a WM_MOUSEMOVE in a test application
2) programmatically call FindWindow() to look for the window name from 1 and get the HWND
3) GetWindowThreadProcessId() returns the process's ID from HWND
4) Enumerate and get the process' main thread from the window handle (I'm pretty sure it's the first one)
5) Send the message using PostThreadMessage()
Posted 07 May 2013 - 03:32 PM
Solved it.Decided to use FindWindow() to get the window's hwnd.The I use SendMessage to create an artificial mouse click.
This might not work the way you expect if you need to send keystrokes though.
In the case of keyboard events more happens when you type than just a WM_* msg popping up in some windows message queue and it is impossible for these events to arise in a non-foreground window under normal use, so merely fabricating windows messages usually doesn't do what you want it to do. The way to do this that actually works for keyboards is to make the target window foreground and use SendInput(...) as someone said above; although, I don't think it is possible to foreground an arbitrary window across processes the way that it was years ago ... so not sure.
Actually I'm slightly surprised sending a WM_LBUTTONDOWN or whatver actually worked. This can have all kinds of unexpected results, if the target window proc uses GetCursorPos() instead of the coordinates in the WPARAM etc.