How to detect mouse clicks without listening to any mouse events defined in the controls?

Is it possible to detect mouse clicks without listening to mouse events defined in wireframe controls?

I mean, I don't want to write code like:

  control.MouseLeftButtonDown += this.HandleMouseLeftButtonDown;

However, I want to know if the user clicks on the screen or not. Is this possible in C # (WPF or Silverlight)?

+3
source share
5 answers

You can register the class handler in a static constructor in your main window, for example:

static MainWindow() {
    EventManager.RegisterClassHandler(typeof (MainWindow),
                                      Mouse.MouseDownEvent,
                                      new MouseButtonEventHandler(OnGlobaMouseDown));
}

It will be the global handler for all MouseDown events.

+8
source

You can use the Win32 API and detect a WM_MOUSE mouse message, something like this:

http://support.microsoft.com/kb/318804

, WM_MOUSE_LL:

http://www.codeproject.com/KB/cs/globalhook.aspx

+4

. , . Mouse.Capture().

+3
+1

" , :

control.MouseLeftButtonDown + = this.HandleMouseLeftButtonDown;"

:

if (Mouse.LeftButton == MouseButtonState.Pressed)
{
     ...
}

.

using System.Windows.Input;

wpf.

0

Source: https://habr.com/ru/post/1789202/


All Articles