I have set up static methods to click on a window from a Windows Forms application as follows
NativeMethods.PostMessage(hWnd, WM_LBUTTONDOWN, IntPtr.Zero, new IntPtr((xpos) | ((ypos) << 16)));
NativeMethods.PostMessage(hWnd, WM_LBUTTONUP, IntPtr.Zero, new IntPtr((xpos) | ((ypos) << 16)));
Where hWnd is the IntPtr to the window I want to click on. And NativeMethods is just a wrapper class to pinvoke the PostMessage/SendMessage methods. and xpos/ypos is passed to the function wrapping this code for coordinates.
The code is very basic (I could paste more if necessary), and does work on most windows, so I know there is no problem there. Where I am running into trouble is when trying to click on a BlueStacks window. I have verified using spy++ that I have the correct 'ui' window to send the PostMessage to (by verifying manual mouse clicks and watching the messages and even replicating the clicks with the above code.
Also when running the code to click on the Bluestacks window spy++ is showing that the PostMessages (and also SendMessages are in fact showing) however the click does not appear to be going through.
I have also tried running the code as administrator and it is still not working on Bluestacks (but does work on other windows ie notepad, word, etc).