private Rectangle GetBSArea() { if (!BlueStackHelper.IsBlueStackRunning) { return(Rectangle.Empty); } Win32.RECT win32rect; if (!Win32.GetClientRect(BlueStackHelper.GetBlueStackWindowHandle(), out win32rect)) { return(Rectangle.Empty); } return(Rectangle.FromLTRB(win32rect.Left, win32rect.Top, win32rect.Right, win32rect.Bottom)); }
static public void BSTest2() { IntPtr hWnd = BlueStackHelper.GetBlueStackWindowHandle();//Win32.FindWindow("Notepad", null); AdvancedMode = false; if (hWnd == IntPtr.Zero) { MessageBox.Show("You should run BlueStack first before trying this test"); } else { Send(hWnd, "2> Does it work? And what for 'éàè'?"); } }
private bool OffsetToBSClientScrrenCoord(ref Rectangle rect) { if (!BlueStackHelper.IsBlueStackRunning) { return(false); } Win32.Point origin = new Win32.Point(0, 0); if (Win32.ClientToScreen(BlueStackHelper.GetBlueStackWindowHandle(), ref origin)) { return(false); } rect.Offset(origin.x, origin.y); return(true); }
/// <summary> /// This capture algorithm should behave as on the background mode of Autoit Coc Bot (as at end of january 2015) /// </summary> /// <param name="left"></param> /// <param name="top"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public Bitmap SnapShot(int left, int top, int width, int height, bool backgroundMode = true) { FreeCurrentImage(); IntPtr hWnd = BlueStackHelper.GetBlueStackWindowHandle(); if (hWnd == IntPtr.Zero) { return(null); } IntPtr hCaptureDC = Win32.GetWindowDC(hWnd); IntPtr hMemDC = Win32.CreateCompatibleDC(hCaptureDC); hBitmap = Win32.CreateCompatibleBitmap(hCaptureDC, width, height); IntPtr hObjOld = Win32.SelectObject(hMemDC, hBitmap); bool result = true; if (backgroundMode) { if (result) { result = Win32.PrintWindow(hWnd, hMemDC, 0); } if (result) { Win32.SelectObject(hMemDC, hBitmap); } } if (result) { result = Win32.BitBlt(hMemDC, 0, 0, width, height, hCaptureDC, left, top, Win32.TernaryRasterOperations.SRCCOPY); } if (result) { BitMap = Bitmap.FromHbitmap(hBitmap); } Win32.DeleteDC(hMemDC); Win32.SelectObject(hMemDC, hObjOld); Win32.ReleaseDC(hWnd, hCaptureDC); Win32.DeleteObject(hBitmap); Debug.Assert(result); return(BitMap); }
// SendMessage and PostMessage should work on hidden forms, use them with the WM_MOUSEXXXX codes and provide the mouse location in the wp or lp parameter, I forget which. public static bool ClickOnPoint2(IntPtr wndHandle, Point clientPoint, int times = 1, int delay = 0) { BlueStackHelper.ActivateBlueStack(); try { /// set cursor on coords, and press mouse if (wndHandle != IntPtr.Zero) { for (int x = 0; x < times; x++) { PostMessageSafe(wndHandle, Win32.WM_LBUTTONDOWN, (IntPtr)0x01, (IntPtr)((clientPoint.X) | ((clientPoint.Y) << 16))); PostMessageSafe(wndHandle, Win32.WM_LBUTTONUP, (IntPtr)0x01, (IntPtr)((clientPoint.X) | ((clientPoint.Y) << 16))); Thread.Sleep(delay); } } } catch (System.ComponentModel.Win32Exception ex) { Debug.Assert(false, ex.Message); return(false); } return(true); }
static public string GetBlueStackExecutablePath() { return(GetExecutablePath(BlueStackHelper.GetBlueStackWindowHandle())); }
static public void SendToBS(string message) { Send(BlueStackHelper.GetBlueStackWindowHandle(), message); }
static public void SendVirtualKeyToBS(VirtualKeys vk) { SendVirtualKey(BlueStackHelper.GetBlueStackWindowHandle(), vk); }