示例#1
0
 private static IntPtr KeyboardHookProc(int code, int wParam, ref SSWindowsFunctions.KeyboardHookStruct lParam)
 {
     if (code >= 0 && (wParam == SSWindowsFunctions.WM_KEYDOWN || wParam == SSWindowsFunctions.WM_SYSKEYDOWN))
     {
         var key = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), lParam.vkCode.ToString());
         if (key == Keys.PrintScreen)
         {
             System.Diagnostics.Debug.WriteLine($"Combination: {key}");
             ((SSBaseHookSystem)GetHookSystem()).InteractionManager.GetCommand <SSKeyboardProvider>().Publish(new SSKeyboardPayload()
             {
                 Value = eScreenshotType.Screen
             });
         }
         else if (LastKey == Keys.LControlKey && key == Keys.NumPad1)
         {
             System.Diagnostics.Debug.WriteLine($"Combination: {LastKey}+{key}");
             ((SSBaseHookSystem)GetHookSystem()).InteractionManager.GetCommand <SSKeyboardProvider>().Publish(new SSKeyboardPayload()
             {
                 Value = eScreenshotType.SelectedArea
             });
         }
         else if (LastKey == Keys.LControlKey && key == Keys.NumPad2)
         {
             System.Diagnostics.Debug.WriteLine($"Combination: {LastKey}+{key}");
             ((SSBaseHookSystem)GetHookSystem()).InteractionManager.GetCommand <SSKeyboardProvider>().Publish(new SSKeyboardPayload()
             {
                 Value = eScreenshotType.SelectedWindow
             });
         }
         LastKey = key;
     }
     return(SSWindowsFunctions.CallNextHookEx(((SSBaseHookSystem)GetHookSystem()).GetHookPtr(), code, (int)wParam, SSWindowsFunctions.StructToPtr(lParam)));
 }
示例#2
0
        private static IntPtr MouseHookProc(int nCode, int wParam, ref SSWindowsFunctions.MouseHookStructLL lParam)
        {
            if (nCode >= 0)
            {
                switch (_screenshotType)
                {
                case eScreenshotType.SelectedWindow:

                    var pt = new SSWindowsFunctions.POINT()
                    {
                        x = lParam.pt.x, y = lParam.pt.y
                    };
                    _selectedWindow = SSWindowsFunctions.WindowFromPoint(pt);
                    _currentDispatcher.BeginInvoke((Action)(() =>
                    {
                        if (_selectedWindow != IntPtr.Zero && _selectedWindow != _oldHwnd)
                        {
                            HighlightingCurrentWindow(_selectedWindow);
                            var textOFSelectedWindow = SSWindowsFunctions.GetText(_selectedWindow);
                            System.Diagnostics.Debug.WriteLine($"Selected window {textOFSelectedWindow}...");
                            _oldHwnd = _selectedWindow;
                        }
                        ProcessSelectingWindow(wParam);
                    }));
                    break;

                case eScreenshotType.SelectedArea:
                    break;
                }
            }
            return(SSWindowsFunctions.CallNextHookEx(GetHookSystem().GetHookPtr(), nCode, wParam, SSWindowsFunctions.StructToPtr(lParam)));
        }
示例#3
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);
            var hwnd = new WindowInteropHelper(this).Handle;

            SSWindowsFunctions.SetWindowExTransparent(hwnd);
        }
示例#4
0
 private void SetHook()
 {
     Contract.Requires(GetHookType() > 0);
     Contract.Requires(GetCallback() != null);
     //IntPtr ptrUser = SSWindowsFunctions.LoadLibrary("User32");
     using (ProcessModule module = Process.GetCurrentProcess().MainModule)
     {
         _hhook = SSWindowsFunctions.SetWindowsHookEx(GetHookType(), GetCallback(), SSWindowsFunctions.GetModuleHandle(module.ModuleName), 0);
     }
 }
示例#5
0
 private static void HighlightingCurrentWindow(IntPtr hWnd)
 {
     SSWindowsFunctions.RECT rc = new SSWindowsFunctions.RECT();
     SSWindowsFunctions.GetWindowRect(hWnd, out rc);
     _highlightWindow.Left   = rc.Left;
     _highlightWindow.Top    = rc.Top;
     _highlightWindow.Width  = rc.Right - rc.Left;
     _highlightWindow.Height = rc.Bottom - rc.Top;
     Debug.WriteLine($"Selected rec = {rc}");
     Debug.WriteLine($"Left:{_highlightWindow.Left} Top:{_highlightWindow.Top} Width:{_highlightWindow.Width} Height:{_highlightWindow.Height}");
     _highlightWindow.Show();
 }
示例#6
0
        public override void StopSystem()
        {
#if LOCAL_DEBUG
            SSWindowsFunctions.UnhookWindowsHookEx(_hhook);
            if (_mouseHookThread != null)
            {
                SSWindowsFunctions.PostThreadMessage(_mouseHookThreadId, 0, UIntPtr.Zero, IntPtr.Zero);
                _mouseHookThread   = null;
                _mouseHookThreadId = 0;
            }
#endif
            InteractionManager.GetCommand <SSSelectionRegionProvider>().Unsubscribe(_selctionAreaToken);
        }
示例#7
0
        public Bitmap GetScreenshtOfSelectedWindow(IntPtr handle)
        {
            Contract.Requires(handle != IntPtr.Zero);

            SSWindowsFunctions.RefreshWindow(handle);

            SSWindowsFunctions.RECT rc = new SSWindowsFunctions.RECT();

            SSWindowsFunctions.GetWindowRect(handle, out rc);
            var bound  = new Rectangle(rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top);
            var result = new Bitmap(bound.Width, bound.Height);

            using (var graphics = Graphics.FromImage(result))
            {
                graphics.CopyFromScreen(new Point(bound.Left, bound.Top), Point.Empty, bound.Size);
            }
            return(result);
        }
示例#8
0
        public override void StartSystem()
        {
#if LOCAL_DEBUG
            _mouseHookThread = new Thread(() =>
            {
                _mouseHookThreadId = (uint)SSWindowsFunctions.GetCurrentThreadId();
                using (ProcessModule module = Process.GetCurrentProcess().MainModule)
                {
                    _hhook = SSWindowsFunctions.SetWindowsHookEx(GetHookType(), GetCallback(), SSWindowsFunctions.GetModuleHandle(module.ModuleName), 0);
                }
                uint msg;
                SSWindowsFunctions.GetMessage(out msg, IntPtr.Zero, 0, 0);
            });
            _mouseHookThread.IsBackground = true;
            _mouseHookThread.Start();
#endif
            _selctionAreaToken = InteractionManager.GetCommand <SSSelectionRegionProvider>().Subscribe(OnSelectionArea);
        }
示例#9
0
 private void ReleaseHook()
 {
     Contract.Requires(_hhook != IntPtr.Zero);
     SSWindowsFunctions.UnhookWindowsHookEx(_hhook);
 }