How to determine if a button click was a mouse click or mouse click in WPF?

Is there an easy way to tell what caused the Click event for a button separately from setting several flags in the mouse / key up / down event handlers? I'm currently interested in distinguishing the mouse from everything else, but it would be nice to handle Stylus and other input types, if possible. Should I create my own button control to achieve this?

Edit: explain why I don’t care: in this particular case, I am trying to implement the “next” and “previous” buttons for my view of the images. The pictures in question may have different sizes, and the positions of the buttons will change (therefore, they will always be located in the center below the picture). It’s very unpleasant to follow these buttons with the mouse if you need to scroll several images, so I want to keep the mouse position constant relative to the pressed button, but only if it was pressed with the mouse and not the keyboard.

Edit2: It doesn't matter if the buttons are at the top or bottom at the bottom, since the center can still change. The "picture viewer" here is just an abstraction, and in this particular case it is important for me that the upper left corner of the image retains its position, but it does not go into the question in order to stop in detail. Scaling the image is not so trivial in such applications, so I want to know the answer to the question that I asked without entering into the discussion of the implementation of the user interface.

+3
source share
5 answers
if (InputManager.Current.MostRecentInputDevice is KeyboardDevice) 
+6
source

Instead, you should handle the MouseXXX, StylusXXx, and KeyboardXXX events.

0
source

Could you talk about why you do not care?

Having written many custom controls over the years, I cannot recall one instance where I was wondering how the click event was raised. (Except that the previous VB6 control life cycle that started focus focus lost focus in a different order, depending on whether you pressed the button, used the accelerator key, or pressed ENTER by default).

0
source

Personally, I find it annoying when people put buttons at the bottom of Windows forms and web pages. Read some of the literature on the user interface, and you will find that most people don’t even go that far unless they find something interesting on the page / form. I like it when you can click on as soon as I find out that the content is not interesting for me, so keep the navigation buttons at the top.

I would put prev / next at the top of the picture where you can control your position. The dances of these buttons around contradict most opinions about UI consistency. Further creation of a different experience for the mouse user and keyboard user also contradicts most modern knowledge of good user interface design.

An alternative is to choose a constant maximum size that the image can receive in the user interface, and if it exceeds this scale, so that it matches, otherwise, allow it to be freely changed inside the frame. This keeps your buttons in the same place, if you absolutely must have them at the bottom.

0
source

You can create an enumeration with various devices, have a global property that you set every time the mouse / keyboard / etc. It is initiated and simply refers to it if necessary.

0
source

All Articles