public void Connect() { try { var frequency = Observable.Interval(TimeSpan.FromMilliseconds(1000d / Framerate), NewThreadScheduler.Default); var cursorPositions = Observable.Create <Point>(s => { return(frequency.Subscribe(_ => { Point point; if (_hook.TryGetCursorPosition(out point)) { s.OnNext(point); } })); }); var simulatedGazePoints = Observable.Create <GazeData>(s => { ScreenInfo screen = null; return(cursorPositions.Subscribe(cursorPosition => { GazeData gaze; if ((screen != null || _screen.TryGetScreenInfo(cursorPosition.X, cursorPosition.Y, out screen)) && screen.Contains(cursorPosition)) { Point2 point = new Point2 ( x: (cursorPosition.X - screen.Left) / (double)screen.Width, y: (cursorPosition.Y - screen.Top) / (double)screen.Height ); gaze = _dataGenerator.CreateValidData(point); } else { gaze = _dataGenerator.CreateInvalidData(); } s.OnNext(gaze); })); }); _gazeSources.OnNext(simulatedGazePoints); //AttachEventHandlers(); //Framerate = 60;//_tracker.GetFrameRate(); //TrackBox = _tracker.GetTrackBox()?.ToTrackBoxCoords(); //DisplayArea = _tracker.GetXConfiguration()?.ToDisplayArea(); //Calibration = _tracker.GetCalibration()?.ToCalibrationResult(); } catch (Exception exception) { throw new ConnectionException("Simulator not found.", exception); } }