Example #1
0
        public bool SnapshotOnMouseEvent(MouseEventType evt, int x, int y)
        {
            bool snap = false;

            if ((evt == MouseEventType.LeftButtonDown) || (evt == MouseEventType.RightButtonDown))
            {
                MouseState mouse = SnapshotEngine.CaptureMouseState(evt);
                if (mouse.ClickOption != _lastMouseState.ClickOption)
                {
                    snap = true;
                }
                else
                {
                    if (evt == MouseEventType.LeftButtonDown)
                    {
                        if (DateTime.Now.Subtract(_prevLButtonDownTime).TotalMilliseconds < 1000)
                        {
                            if ((Math.Abs(mouse.X - _lastMouseState.X) < 15) && (Math.Abs(mouse.Y - _lastMouseState.Y) < 10))
                            {
                                snap = true;
                            }
                        }
                        _prevLButtonDownTime = DateTime.Now;
                    }
                    if ((Math.Abs((int)(mouse.X - _lastMouseState.X)) > 5) || (Math.Abs((int)(mouse.Y - _lastMouseState.Y)) > 5))
                    {
                        snap = true;
                    }
                }
                _isLastEventFromKeyboard = false;
                _lastMouseTime           = DateTime.Now;
            }
            TraceLogger.Instance.WriteLineInfo("SnapshotOnMouseEvent: " + snap.ToString());
            return(snap);
        }
Example #2
0
        private void SnapshotWorker(object state)
        {
            TraceLogger.Instance.WriteEntracne();
            IRawEvent[] evts = state as IRawEvent[];
            Debug.Assert(evts != null && evts.Length > 0);
            var lastEvt = evts[evts.Length - 1];

            try
            {
                if (!IsRecording)
                {
                    return;
                }
                TraceLogger.Instance.WriteLineVerbos("SnapshotWorker do record at ticks: " + DateTime.Now.Ticks);

                WindowInfo wi    = SnapshotEngine.GetActiveProcessWindow();
                Snapshot   sshot = new Snapshot()
                {
                    SessionId  = _session.SessionId,
                    SnapshotId = Guid.NewGuid().ToString("n"),
                    SnapTime   = DateTime.Now,

                    ProcessId   = wi.ProcessId,
                    ProcessName = wi.ProcessName,
                    FileName    = wi.FileName,

                    ScreenWidth  = wi.ScreenWidth,
                    ScreenHeight = wi.ScreenHeight,

                    WindowHandle = wi.WindowHandle,
                    WindowRect   = wi.WindowRect,
                    WindowTitle  = wi.WindowTitle,
                    WindowUrl    = wi.WindowUrl,
                };
                // image
                if (Global.Config.RecordImage)
                {
                    Image img = WindowCaptureEngine.CaptureScreen();
                    if (Global.Config.DebugDumpOriginal)
                    {
                        try
                        {
                            string path = Path.Combine(CacheManager.CachePath, string.Format(@"{0}\{1}.png", SessionId, sshot.SnapshotId));
                            (img as Bitmap).Save(path, System.Drawing.Imaging.ImageFormat.Png);
                        }
                        catch (Exception ex) { TraceLogger.Instance.WriteException(ex); }
                    }
                    bool isGrayScale;
                    sshot.ImageData   = GetImageData(img, out isGrayScale);
                    sshot.IsGrayScale = isGrayScale;
                    sshot.Mouse       = GetMouseState(lastEvt.MouseEvent);
                }

                // text
                if (lastEvt.IsKeyEvent)
                {
                    sshot.ControlText = TextCaptureEngine.GetControlText(new IntPtr(wi.WindowHandle));
                }
                sshot.InputText  = _policy.GetText(evts);
                sshot.EventsData = RawInputEvent.ToBinary(evts);

                // flush
                _cacheManager.WriteSnapshot(_session, sshot);

                // set active
                _session.LastActiveTime = DateTime.Now;

                // debug
                if (Global.Config.DebugDumpText)
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(sshot.InputText))
                        {
                            File.AppendAllText(Path.Combine(CacheManager.CachePath, "InputText.txt"), sshot.InputText + Environment.NewLine);
                        }
                        if (!string.IsNullOrEmpty(sshot.ControlText))
                        {
                            File.AppendAllText(Path.Combine(CacheManager.CachePath, "ControlText.txt"), sshot.ControlText + Environment.NewLine);
                        }
                        if (!string.IsNullOrEmpty(sshot.WindowUrl))
                        {
                            File.AppendAllText(Path.Combine(CacheManager.CachePath, "WindowUrl.txt"), sshot.WindowUrl + Environment.NewLine);
                        }
                    }
                    catch (Exception ex) { TraceLogger.Instance.WriteException(ex); }
                }
            }
            catch (Exception ex) { TraceLogger.Instance.WriteException(ex); }
            TraceLogger.Instance.WriteExit();
        }