Ejemplo n.º 1
0
        private void btnRecord_Click(object sender, RoutedEventArgs e)
        {
            SelectChangedSource = UiSelectChangedSource.SelectChangeFinished;

            if (IsRecording == false)
            {
                MouseKeyboardEventHandler.Init();

                btnRecord.Content            = "Pause";
                textBoxRecording.Text        = "Recording";
                gridTextRecording.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0));

                IsRecording = true;
                AppInsights.LogEvent("Record");
            }
            else
            {
                IsRecording = false;

                MouseKeyboardEventHandler.UnInit();

                btnRecord.Content            = "Record";
                textBoxRecording.Text        = "";
                gridTextRecording.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF));

                AddInspectUi(null); // remove last Inspect node
                AppInsights.LogEvent("Pause");
            }
        }
        public static IntPtr KeyboardHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0 || MouseKeyboardEventHandler.s_threadRecorder == null || MainWindow.s_mainWin.IsRecording == false)
            {
                return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
            }

            KeyboardEvents  kEvent = (KeyboardEvents)wParam.ToInt32();
            KBDLLHOOKSTRUCT kbd    = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));

            int         scanCode = (int)kbd.scanCode;
            VirtualKeys vk       = (VirtualKeys)kbd.vkCode;

            if (vk == VirtualKeys.VK_PAUSE && kEvent == KeyboardEvents.KeyDown)
            {
                s_bPauseMouseKeyboard = !s_bPauseMouseKeyboard;

                if (s_bPauseMouseKeyboard == true)
                {
                    NativeMethods.PostMessage(MainWindow.s_windowHandle, (int)MainWindow.UiThreadTask.PauseRecording, 0, 0);
                }
                else
                {
                    NativeMethods.PostMessage(MainWindow.s_windowHandle, (int)MainWindow.UiThreadTask.Active, 0, 0);
                }
            }

            if (s_bPauseMouseKeyboard == false)
            {
                MouseKeyboardEventHandler.RecordKey(kEvent, vk, scanCode);
            }

            return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
        }
Ejemplo n.º 3
0
        private void Window_Closed(object sender, EventArgs e)
        {
            MouseKeyboardEventHandler.UnInit();
            MouseKeyboardHook.StopHook();
            s_mainWin = null;

            System.Windows.Interop.HwndSource.FromHwnd(s_windowHandle).RemoveHook(RunOnUiThread);

            AppInsights.LogEvent("Window_Closed");
        }
        public static IntPtr MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0 || MouseKeyboardEventHandler.s_threadRecorder == null || s_bPauseMouseKeyboard == true)
            {
                return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
            }

            MSLLHOOKSTRUCT mhs  = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
            int            left = mhs.pt.X;
            int            top  = mhs.pt.Y;

            //skip if cursor is on this app
            IntPtr hwnd = NativeMethods.WindowFromPoint(left, top);

            if (hwnd == MainWindow.s_windowHandle)
            {
                MouseKeyboardEventHandler.ResetRecordTimer();
                return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
            }

            switch (wParam.ToInt32())
            {
            case WM_MOUSEMOVE:
                MouseKeyboardEventHandler.MouseMove(left, top);
                break;

            case WM_MOUSEWHEEL:
                short zDelta = (short)(mhs.mouseData >> 16);
                MouseKeyboardEventHandler.MouseWheel(left, top, zDelta);
                break;

            case WM_LBUTTONDOWN:
                MouseKeyboardEventHandler.LeftMouseDown(left, top);
                break;

            case WM_LBUTTONUP:
                MouseKeyboardEventHandler.LeftMouseUp(left, top);
                break;

            case WM_RBUTTONDOWN:
                MouseKeyboardEventHandler.RightMouseDown(left, top);
                break;

            case WM_RBUTTONUP:
                MouseKeyboardEventHandler.RightMouseUp(left, top);
                break;
            }

            return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
        }