Example #1
0
        /// <summary>
        /// Captures a screenshot. Remember, you should always use this class from the same thread.
        /// </summary>
        /// <returns></returns>
        public FragmentedImage Capture(SHRDLib.NetCommand.DesktopScreen screen)
        {
            if (screen == null)
            {
                throw new NullReferenceException("screen cannot be null");
            }
            long thisMs = timing.ElapsedMilliseconds;

            // Learn about the display configuration
            if (displaySettingsChanged)
            {
                displaySettingsChanged = false;
                ClearCaptureHandle();
                DesktopManager.ShouldReassociate = true;
            }
            if (DesktopManager.ShouldReassociate || thisMs > nextDesktopCheck)
            {
                DesktopManager.ShouldReassociate = false;
                nextDesktopCheck = thisMs + desktopCheckInterval;
                if (DesktopManager.AssociateCurrentThreadWithDefaultDesktop())
                {
                    ClearCaptureHandle();                     // Desktop was changed.
                }
            }
            // Capture
            Screenshot screenshot = CaptureScreenshot(screen.X, screen.Y, screen.Width, screen.Height);

            if (screenshot == null)
            {
                return(new FragmentedImage());
            }
            FragmentedImage img = new FragmentedImage(new MovedImageFragment[0], new DirtyImageFragment[] { new DirtyImageFragment(screen.Y, screen.X + screen.Width, screen.Height + screen.Y, screen.X, screenshot) });

            return(img);
        }
Example #2
0
        //~InputEmulator()
        //{
        //	if (isDisposed)
        //		return;
        //	Dispose(false);
        //}

        //public void Dispose()
        //{
        //	if (isDisposed)
        //		return;
        //	Dispose(true);
        //	GC.SuppressFinalize(this);
        //}

        //protected void Dispose(bool disposing)
        //{
        //	isDisposed = true;
        //}

        public void EmulateInput(SharedMemoryStream sm)
        {
            DesktopManager.AssociateCurrentThreadWithDefaultDesktop();
            InputType type = (InputType)sm.ReadByte();

            switch (type)
            {
            case InputType.KeyDown:
            case InputType.KeyUp:
            {
                int          keyCode   = sm.ReadInt32();
                ModifierKeys modifiers = (ModifierKeys)sm.ReadUInt32();
                bool         isUp      = type == InputType.KeyUp;
                EmulateKeyboard(keyCode, modifiers, isUp);
            }
            break;

            case InputType.MouseMove:
            {
                float X = sm.ReadFloat();
                float Y = sm.ReadFloat();
                EmulateMouseMove(X, Y);
            }
            break;

            case InputType.MouseButtonDown:
            case InputType.MouseButtonUp:
            {
                MouseButton button = (MouseButton)sm.ReadByte();
                bool        isUp   = type == InputType.MouseButtonUp;
                EmulateMouseButton(button, isUp);
            }
            break;

            case InputType.MouseWheel:
            {
                short deltaX = sm.ReadInt16();
                short deltaY = sm.ReadInt16();
                if (deltaX != 0)
                {
                    EmulateMouseWheelX(deltaX);
                }
                if (deltaY != 0)
                {
                    EmulateMouseWheelY(deltaY);
                }
            }
            break;

            default:
                break;
            }
        }