Exemple #1
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;
            }
        }
Exemple #2
0
        private static void mainThreadRunner()
        {
            try
            {
                screenCapturer = new AdvScreenCapture();
                dxgiDuplicator = new DxgiOutputDuplicator(0, 0);
                inputEmulator  = new InputEmulator();
                Logger.Info("Application start shared memory id " + streamerArgs.SharedMemoryId);
                int ownerPID = streamerArgs.ServiceProcessId == null ? 0 : streamerArgs.ServiceProcessId.Value;
                using (SharedMemoryStream sm = SharedMemoryStream.OpenSharedMemoryStream(streamerArgs.SharedMemoryId, ownerPID))
                {
                    try
                    {
                        static_sm = sm;
                        thrDesktopCapture.Start();
                        while (!isExiting)
                        {
                            Command commandCode = (Command)sm.ReadByte();
                            // Handle
                            switch (commandCode)
                            {
                            case Command.GetScreenCapture:
                                ImgFlags imgFlags    = (ImgFlags)sm.ReadByte();
                                byte     jpegQuality = (byte)sm.ReadByte();
                                desktopCaptureTasks.Enqueue(new DesktopCaptureTask(imgFlags, jpegQuality));
                                break;

                            //case Command.CaptureCompressedDesktopImage:
                            //	CaptureCompressedDesktopImage(sm);
                            //	break;
                            case Command.ReproduceUserInput:
                                inputEmulator.EmulateInput(sm);
                                break;

                            case Command.GetDesktopInfo:
                                lock (sm)
                                {
                                    desktopInfo.WriteToDataStream(sm);
                                }
                                break;

                            case Command.KeepAlive:
                                break;

                            default:
                                Logger.Debug("Unsupported command code received: " + commandCode);
                                lock (sm)
                                {
                                    sm.WriteByte((byte)Command.Error_CommandCodeUnknown);
                                }
                                break;
                            }
                        }
                    }
                    finally
                    {
                        static_sm = null;
                    }
                }
            }
            catch (ThreadAbortException) { }
            catch (StreamDisconnectedException ex)
            {
                Logger.Info("Exiting because: " + ex.Message);
            }
            catch (Exception ex)
            {
                Logger.Debug(ex);
                Logger.Info("Exiting due to main thread runner exception");
            }
            finally
            {
                Try.Catch(() => { dxgiDuplicator?.Dispose(); });
                Try.Catch(() => { screenCapturer?.Dispose(); });
                //Try.Catch(() => { inputEmulator?.Dispose(); });
                RobustExit();
            }
        }