0

I need to write an auto click C# application for Bluestack in background. I tried using Autoit api and I can click or sendkey, but it does not support drag & drop. I found a solution using "user32.dll" PostMessage on C#, but it doesn't seem to work in window 10 anymore.

Anyone have other solutions. Please help. Thanks a lot!

[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

PostMessage(handle, (uint)WMessages.WM_LBUTTONDOWN, 0, MAKELPARAM(400, 400));
user4157124
  • 2,809
  • 13
  • 27
  • 42
Monster
  • 15
  • 5

1 Answers1

2

Make Sure you are using correct window handle for sending click. It is with name BlueStacks Android PluginAndroid{X} {X=>instance of android running}
enter image description here

I tries sending message to that handle of window and it worked like charm on win10.

Win32.SendMessage(0x00060714, Win32.WM_LBUTTONDOWN, 0x00000001, 0x1E5025B);

Here is the winapi class I picked from here

    public class Win32
    {
        // The WM_COMMAND message is sent when the user selects a command item from 
        // a menu, when a control sends a notification message to its parent window, 
        // or when an accelerator keystroke is translated.
        public const int WM_KEYDOWN = 0x100;
        public const int WM_KEYUP = 0x101;
        public const int WM_COMMAND = 0x111;
        public const int WM_LBUTTONDOWN = 0x201;
        public const int WM_LBUTTONUP = 0x202;
        public const int WM_LBUTTONDBLCLK = 0x203;
        public const int WM_RBUTTONDOWN = 0x204;
        public const int WM_RBUTTONUP = 0x205;
        public const int WM_RBUTTONDBLCLK = 0x206;

        // The FindWindow function retrieves a handle to the top-level window whose
    // class name and window name match the specified strings.
    // This function does not search child windows.
    // This function does not perform a case-sensitive search.
    [DllImport("User32.dll")]
    public static extern int FindWindow(string strClassName, string strWindowName);

    // The FindWindowEx function retrieves a handle to a window whose class name 
    // and window name match the specified strings.
    // The function searches child windows, beginning with the one following the
    // specified child window.
    // This function does not perform a case-sensitive search.
    [DllImport("User32.dll")]
    public static extern int FindWindowEx(
        int hwndParent,
        int hwndChildAfter,
        string strClassName,
        string strWindowName);


    // The SendMessage function sends the specified message to a window or windows. 
    // It calls the window procedure for the specified window and does not return
    // until the window procedure has processed the message. 
    [DllImport("User32.dll")]
    public static extern Int32 SendMessage(
        int hWnd,               // handle to destination window
        int Msg,                // message
        int wParam,             // first message parameter
        [MarshalAs(UnmanagedType.LPStr)] string lParam); // second message parameter

    [DllImport("User32.dll")]
    public static extern Int32 SendMessage(
        int hWnd,               // handle to destination window
        int Msg,                // message
        int wParam,             // first message parameter
        int lParam);            // second message parameter
}
Aman Seth
  • 196
  • 6
  • Thank you very much Aman Seth, i found this tool and it worked like a charm. Have nice day :) – Monster Dec 19 '17 at 17:24
  • Hi Aman Seth, did you have solution for simulate drag&drop on BS, i tried WM_LBUTTONDOWN and then WM_MOUSEMOVE but not work, thank you :D – Monster Jan 05 '18 at 04:17