예제 #1
0
        /// <summary>
        /// Generates a mouse move event
        /// </summary>
        /// <param name="x">X position/offset of screen</param>
        /// <param name="y">Y position/offset of screen</param>
        /// <param name="absolute">Use absolute coordinates or relative coordinates</param>
        public void MouseMove(int x, int y, bool absolute = true)
        {
            USER32.INPUT[] inputs = new USER32.INPUT[1];

            USER32.INPUT si = new USER32.INPUT();
            si.type           = USER32.INPUTFlags.INPUT_MOUSE;
            si.mi             = new USER32.MOUSEINPUT();
            si.mi.dx          = x;
            si.mi.dy          = y;
            si.mi.mouseData   = 0;
            si.mi.time        = 0;
            si.mi.dwExtraInfo = USER32.GetMessageExtraInfo();

            if (absolute)
            {
                int _v = USER32.GetSystemMetrics(SystemMetric.SM_CXSCREEN);
                _v = USER32.GetSystemMetrics(SystemMetric.SM_CYSCREEN);
                float wpx = 65535.0f / USER32.GetSystemMetrics(SystemMetric.SM_CXSCREEN);
                float hpx = 65535.0f / USER32.GetSystemMetrics(SystemMetric.SM_CYSCREEN);
                si.mi.dx      = (int)(si.mi.dx * wpx);
                si.mi.dy      = (int)(si.mi.dy * hpx);
                si.mi.dwFlags = (uint)(USER32.INPUTFlags.MOUSEEVENTF_MOVE | USER32.INPUTFlags.MOUSEEVENTF_ABSOLUTE | USER32.INPUTFlags.MOUSEEVENTF_VIRTUALDESK);
            }
            else
            {
                si.mi.dwFlags = (uint)USER32.INPUTFlags.MOUSEEVENTF_MOVE;
            }

            inputs[0] = si;
            USER32.SendInput(1, inputs, Marshal.SizeOf(si));
        }
예제 #2
0
        public static Size GetDesktopSize()
        {
            int width  = USER32.GetSystemMetrics(USER32.SM_CXSCREEN);   // width of desktop
            int height = USER32.GetSystemMetrics(USER32.SM_CYSCREEN);   // height of desktop

            return(new Size(width, height));
        }
예제 #3
0
        /// <summary>
        /// Captures the desktop to a bitmap image
        /// </summary>
        /// <returns>bitmap image of the desktop</returns>
        public static Bitmap Desktop()
        {
            int    width       = USER32.GetSystemMetrics(USER32.SM_CXSCREEN); // width of desktop
            int    height      = USER32.GetSystemMetrics(USER32.SM_CYSCREEN); // height of desktop
            IntPtr desktopHWND = USER32.GetDesktopWindow();                   // window handle for desktop

            return(Window(desktopHWND, 0, 0, width, height));                 // return bitmap for desktop
        }                                                                     // end method Desktop
예제 #4
0
 public static Bitmap GetDesktopImage()
 {
     return(GetImageFromHandle(
                //Here we get the handle to the desktop device context.
                USER32.GetDesktopWindow(),
                //We pass SM_CXSCREEN constant to GetSystemMetrics to get the X coordinates of screen.
                USER32.GetSystemMetrics(SCREENCAPTURE.SM_CXSCREEN),
                //We pass SM_CYSCREEN constant to GetSystemMetrics to get the Y coordinates of screen.
                USER32.GetSystemMetrics(SCREENCAPTURE.SM_CYSCREEN)
                ));
 }