Esempio n. 1
0
        public Recorder(Test test)
        {
            this.test = test;

            ScreenshotsEnabled = true;
            CurrentRecorderState = RecorderState.Stopped;

            globalHooker = new GlobalHooker();
            globalHooker2 = new GlobalHooker();

            keyboardHookListener = new KeyboardHookListener(globalHooker2);
            mouseHookListener = new MouseHookListener(globalHooker);

            keyboardHookListener.KeyDown += KeyboardHookListenerOnKeyDown;
            keyboardHookListener.KeyUp += KeyboardHookListenerOnKeyUp;

            mouseHookListener.MouseDown += MouseHookListenerOnMouseDown;
            mouseHookListener.MouseUp += MouseHookListenerOnMouseUp;

            mouseHookListener.Enabled = false;
            mouseHookListener.Enabled = false;

            keyboardHelper = new KeyboardHelper();

            currentInputType = InputType.None;

            InsertPosition = -1;
        }
Esempio n. 2
0
        public HIDListener(GUI o)
        {
            Debug.WriteLine("HIDListen instansiated ");
            owner = o;
            Thread thread = Thread.CurrentThread;

            owner.ServiceDebugConsole("HIDListener started on Thread : " + thread.Name + thread.ManagedThreadId);

            m_KeyboardHookManager = new KeyboardHookListener(new GlobalHooker());
            m_KeyboardHookManager.Enabled = true;

            m_MouseHookManager = new MouseHookListener(new GlobalHooker());
            m_MouseHookManager.Enabled = true;

            Hooker hook;
            hook = new GlobalHooker();
            m_KeyboardHookManager.Replace(hook);
            //m_KeyboardHookManager.Enabled = true;
            m_MouseHookManager.Replace(hook);

            m_MouseHookManager.MouseMove += HookManager_MouseMove;
            m_MouseHookManager.MouseClickExt += HookManager_MouseClick;
            m_MouseHookManager.MouseUp += HookManager_MouseUp;
            m_MouseHookManager.MouseDown += HookManager_MouseDown;
            m_MouseHookManager.MouseDoubleClick += HookManager_MouseDoubleClick;
            m_MouseHookManager.MouseWheel += HookManager_MouseWheel;
               // m_MouseHookManager.MouseDownExt += HookManager_Supress;
            m_KeyboardHookManager.KeyDown += HookManager_KeyDown;
            m_KeyboardHookManager.KeyUp += HookManager_KeyUp;
            m_KeyboardHookManager.KeyPress += HookManager_KeyPress;

            owner.ServiceDebugConsole("HIDListener start Completed : " + thread.Name);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var globalHooker = new GlobalHooker();
            var mouseListenerHooker = new MouseHookListener(globalHooker);

            var mouseDownRecorder = new MouseDownRecorder(mouseListenerHooker);
            mouseDownRecorder.Register(OnActionOccured);
            System.Console.ReadLine();
        }
Esempio n. 4
0
        public MainWindow()
        {
            InitializeComponent();
            var globalHooker = new GlobalHooker();
            var mouseListenerHooker = new MouseHookListener(globalHooker);
            var mouseDownListener = new MouseDownActionListener(mouseListenerHooker);

            var mouseDownRecorder = new MouseDownActionPublisher();
            mouseDownRecorder.Register(mouseDownListener);
            mouseDownRecorder.UserActionPublished += mouseDownRecorder_UserActionPublished;
            mouseListenerHooker.Start();
        }
Esempio n. 5
0
        public HIDListener()
            : base()
        {
            Hooker hook = new GlobalHooker();
            //Keyboard Hook
            m_KeyboardHookManager = new KeyboardHookListener(new GlobalHooker());
            m_KeyboardHookManager.Replace(hook);
            m_KeyboardHookManager.Enabled = true;
            //Mouse Hook
            m_MouseHookManager = new MouseHookListener(new GlobalHooker());
            m_MouseHookManager.Enabled = true;
            //Set up Keyboard deligate methods.
            m_KeyboardHookManager.KeyDown += HookManager_KeyDown;
            m_KeyboardHookManager.KeyUp += HookManager_KeyUp;

            m_MouseHookManager.MouseMove += HookManager_MouseMove;
            m_MouseHookManager.MouseUp += HookManager_MouseUp;
            m_MouseHookManager.MouseDown += HookManager_MouseDown;
        }
        private void ExecuteSelectImageCommand()
        {
            testItemController.MinimizeTestItemEditorWindow();

            Window window = new Window();
            window.Height = SystemParameters.VirtualScreenHeight;
            window.Width = SystemParameters.VirtualScreenWidth;
            bool doPicture = false;

            Canvas canvas = new Canvas();
            canvas.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(100, 100,100,100));
            Rectangle rectangle = new Rectangle();
            rectangle.StrokeThickness = 2;
            rectangle.Stroke = Brushes.Red;
            rectangle.Height = 0;
            rectangle.Width = 0;
            Canvas.SetTop(rectangle, 0);
            Canvas.SetLeft(rectangle, 0);
            System.Drawing.Point point = new System.Drawing.Point();

            GlobalHooker hooker = new GlobalHooker();
            MouseHookListener listener = new MouseHookListener(hooker);

            bool isMouseDown = false;
            bool isComplete = false;
            System.Drawing.Point topLeft = new System.Drawing.Point();
            System.Drawing.Point bottomRight = new System.Drawing.Point();

            listener.MouseDown += (o, args) =>
            {
                isMouseDown = true;
                topLeft = System.Windows.Forms.Cursor.Position;
            };

            listener.MouseUp += (o, args) =>
            {

                isMouseDown = false;
                bottomRight = System.Windows.Forms.Cursor.Position;
                isComplete = true;
            };

            listener.Enabled = true;

            Task task = new Task(() =>
            {
                listener.Enabled = true;

                while (!isComplete)
                {
                    Thread.Sleep(250);
                    while (isMouseDown)
                    {
                        point = System.Windows.Forms.Cursor.Position;

                        Rect bounds = new Rect(new Point(topLeft.X, topLeft.Y), new Point(point.X, point.Y));

                        Thread.Sleep(100);
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            rectangle.Width = bounds.Width;
                            rectangle.Height = bounds.Height;
                            Canvas.SetTop(rectangle, bounds.Y);
                            Canvas.SetLeft(rectangle, bounds.X);
                        }));
                    }
                }

            });

            canvas.Children.Add(rectangle);
            window.Left = 0;
            window.Top = 0;

            window.Content = canvas;
            window.WindowStyle = new WindowStyle();
            window.ShowInTaskbar = false;
            window.AllowsTransparency = true;

            Bitmap screenshot = new Bitmap(1,1);

            BitmapImage bitmapImage = new BitmapImage();

            window.Topmost = true;

            Task waitTask = new Task(() =>
            {
                Thread.Sleep(3000);
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    using (MemoryStream memory = new MemoryStream())
                    {
                        screenshot = Camera.Capture(0, ScreenCaptureMode.Screen);
                        screenshot.Save(memory, ImageFormat.Png);
                        memory.Position = 0;

                        bitmapImage.BeginInit();
                        bitmapImage.StreamSource = memory;
                        bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                        bitmapImage.EndInit();
                    }

                    window.Background = new ImageBrush(bitmapImage);

                    window.Show();
                }));

            });

            task.ContinueWith(t =>
            {
                System.Drawing.Rectangle systemRect = new System.Drawing.Rectangle(topLeft.X, topLeft.Y,
                    bottomRight.X-topLeft.X, bottomRight.Y-topLeft.Y);

                Bitmap tempBitmap = new Bitmap(systemRect.Width, systemRect.Height);

                using (Graphics g = Graphics.FromImage(tempBitmap))
                {
                    g.DrawImage(screenshot, new System.Drawing.Rectangle(0, 0, tempBitmap.Width, tempBitmap.Height),
                        systemRect, GraphicsUnit.Pixel);
                }

                Image = tempBitmap;

                TestItem testItem = testItemController.CurrentTestItem;
                OperationParameter operationParameter = testItem.Operation.GetParameterNamed("Image");
                operationParameter.Value = Image;

                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    window.Close();
                    Thread.Sleep(500);
                    testItemController.RestoreTestItemEditorWindow();
                    Thread.Sleep(500);
                    testItemController.RestoreTestItemEditorWindow();
                }));

            });

            waitTask.Start();
            waitTask.ContinueWith(t => task.Start());

            window.Closed += (o, args) =>
            {
                doPicture = false;
                task.Dispose();
            };
        }
Esempio n. 7
0
        private void radioHooksType_CheckedChanged(object sender, EventArgs e)
        {
            Hooker hook;

            if (radioApplication.Checked)
            {
                hook = new AppHooker();
            }
            else
            {
                hook = new GlobalHooker();
            }

            m_KeyboardHookManager.Replace(hook);
            m_MouseHookManager.Replace(hook);
        }
        private void ExecuteGetObjectCommand()
        {
            testItemController.MinimizeTestItemEditorWindow();

            Window window = new Window();
            window.Height = SystemParameters.VirtualScreenHeight;
            window.Width = SystemParameters.VirtualScreenWidth;
            bool doPicture = false;

            Canvas canvas = new Canvas();
            Rectangle rectangle = new Rectangle();
            rectangle.StrokeThickness = 3;
            rectangle.Stroke = Brushes.Red;
            rectangle.Height = 0;
            rectangle.Width = 0;
            Canvas.SetTop(rectangle, 0);
            Canvas.SetLeft(rectangle, 0);
            UIItem currentUIItem = null;
            System.Drawing.Point point = new System.Drawing.Point();

            Task task = new Task(() =>
            {
                doPicture = true;
                UIItem prevUIItem = null;

                GlobalHooker hooker = new GlobalHooker();
                KeyboardHookListener listener = new KeyboardHookListener(hooker);
                listener.Enabled = true;

                listener.KeyDown += (o, args) =>
                {
                    if (args.Shift && args.Control && args.KeyCode == Keys.A)
                    {
                        doPicture = false;

                    }
                };

                while (doPicture)
                {
                    point = Cursor.Position;
                    currentUIItem = ExternalAppInfoManager.GetControl(System.Windows.Forms.Cursor.Position);

                    if (currentUIItem.AutomationElement.Current.ProcessId == Process.GetCurrentProcess().Id)
                        currentUIItem = prevUIItem;

                    if (currentUIItem == null)
                        continue;

                    Rect bounds = currentUIItem.AutomationElement.Current.BoundingRectangle;

                    Thread.Sleep(250);
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        rectangle.Width = bounds.Width;
                        rectangle.Height = bounds.Height;
                        Canvas.SetTop(rectangle, bounds.Y);
                        Canvas.SetLeft(rectangle, bounds.X);
                    }));
                    prevUIItem = currentUIItem;
                }

            });

            canvas.Children.Add(rectangle);
            window.Left = 0;
            window.Top = 0;

            window.Content = canvas;
            window.WindowStyle = new WindowStyle();
            window.ShowInTaskbar = false;
            window.AllowsTransparency = true;
            window.Background = Brushes.Transparent;
            window.Topmost = true;
            window.Show();
            task.Start();

            task.ContinueWith(t =>
            {
                UIItem = currentUIItem;

                TestItem onScreenValidation = testItemController.CurrentTestItem;

                if (onScreenValidation.Operation != null)
                {
                    OperationParameter operationParameterX = onScreenValidation.Operation.GetParameterNamed("ClientX");
                    OperationParameter operationParameterY = onScreenValidation.Operation.GetParameterNamed("ClientY");

                    if (operationParameterX != null && operationParameterY != null)
                    {
                        operationParameterX.Value = point.X - UIItem.Bounds.X;
                        operationParameterY.Value = point.Y - UIItem.Bounds.Y;
                    }
                }

                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    window.Close();
                    Thread.Sleep(500);
                    testItemController.RestoreTestItemEditorWindow();
                    Thread.Sleep(500);
                    testItemController.RestoreTestItemEditorWindow();
                }));

            });

            window.Closed += (o, args) =>
            {
                doPicture = false;
                task.Dispose();
            };
        }