Beispiel #1
0
 private RawInputWnd CreateRawInputWnd()
 {
     // if create RawInputWnd fail, exit process to try again.
     try
     {
         RawInputWnd form = null;
         form = new RawInputWnd();
         form.RawInputMouseEvent += (e, x, y) =>
         {
             TraceLogger.Instance.WriteLineVerbos("RawInputMouseEvent: " + e);
             var evt = new RawInputEvent(e, (short)x, (short)y, DateTime.Now);
             if (_policy.FireEvent(evt))
             {
                 TraceLogger.Instance.WriteLineVerbos("Push event: " + evt.Evt);
                 _events.Enqueue(evt);
             }
         };
         form.RawInputKeyboardEvent += (e, key) =>
         {
             TraceLogger.Instance.WriteLineVerbos("RawInputKeyboardEvent: " + e);
             var evt = new RawInputEvent(e, key, DateTime.Now);
             if (_policy.FireEvent(evt))
             {
                 TraceLogger.Instance.WriteLineVerbos("Push event: " + evt.Evt);
                 _events.Enqueue(evt);
             }
             ///? GetKeyState to get state of shift, ctrl and alt, mask it in key value by Keys.Shift/Control/Alt.
         };
         return(form);
     }
     catch (Exception ex)
     {
         TraceLogger.Instance.WriteException(ex);
         Application.Exit();
         return(null);
     }
 }
Beispiel #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();
        }