I worked on input input in a WPF application. What makes this project difficult is that I need to be able to enter input into the application, even if it is running in the background (that is, another application has input focus). Therefore, the use of the SendInput () function is out of the question.
While my keyboard is working, but I have problems with mouse input.
I used Spy ++ to monitor window messages that are sent to the WPF window when I physically click the mouse. Then I simply process the same mouse messages (e.g. WM_LBUTTONDOWN and WM_LBUTTONUP ) manually and explicitly send them to the WPF window to emulate mouse input.
Unfortunately, this does not work properly (even if I did not set the WPF window as the foreground for testing purposes).
I added a button to my test WPF window, which when clicked displays a message box. Entering the corresponding mouse messages when I manually positioned the cursor over the button does not cause the button to be pressed, however (i.e., the Click event is not triggered by the WPF framework).
If I add a mouse click handler to the actual dialog box (client area), this handler will trigger a call if I place the cursor over the dialog itself and add the same window messages as before:
this.MouseLeftButtonDown += WndMouseDown; public void WndMouseDown(object sender, EventArgs e) { ... }
Oddly enough, if I changed the button click mode to click (that is, assuming I clicked the mouse down, and not the default mouse), the button click event now fires when I insert the same messages as before. (It is worth mentioning that the handler from the above example works correctly for both the mouse and ups, so it would seem that the WPF environment successfully processes both messages.)
It seems that there are some other criteria that must be met in order for the click event to be fired using the WPF environment. Does anyone know how mouse input is handled internally by WPF, or why doesn't it interpret my mouse up and down messages as a click on a button?
(Itβs worth mentioning that this approach [sending window messages] works fine in regular Win32 windows, such as the Start-> Run dialog. The difference is that WPF has only one physical Win32 window, and the rest means that so that all window messages go to this top-level window, and not to the actual button.)
I searched high and low to answer this question and would appreciate any thoughts or ideas.