"When the application window has no focus, sometimes the click handler is not called when the button is clicked.
System:
Windows 8.1 with a multi-touch input device.
Software:
A simple WPF 4.5.2 application with one button that registers when a click handler is called (just create a new project and add a button with a click handler in MainWindow).
Phenomenon:
Typically, when a button is touched, its click handler is called. But when the application window does not have focus, sometimes the click handler is not called when the button is pressed (although the color of the button changes to blue). When the application window already has focus, touching the button works all the time. This happens only occasionally, but occurs in different systems with different sensor equipment (all windows 8.1). I have never experienced this on windows 7. It works with the mouse, regardless of whether the window is focused or not.
(occurs in release and debug mode, with the application and without a debugger)
Testing:
I checked various touch settings in the windows and played with it. I also recalibrate the sensor system -> no differences.
When checking mouse buttons and WPF touch events in case of an error, the last event received is PreviewMouseUp, but not Click!
When I look at the received window messages (spy ++), I get the following (WM_IME_SETCONTEXT, WM_GETTEXT, WM_NCHITTEST, WM_GETOBJECT deleted for a better overview):
The click was received:
R WM_POINTERACTIVATE pmsd->lResult:FFFFFFFFFFFFFFFF S WM_MOUSEACTIVATE hwndTopLevel:000503F8 nHittest:HTCLIENT uMsg:WM_POINTERDOWN R WM_MOUSEACTIVATE fuActivate:MA_ACTIVATE S WM_WINDOWPOSCHANGING lpwp:000000E9E3D9E410 R WM_WINDOWPOSCHANGING S WM_WINDOWPOSCHANGED lpwp:000000E9E3D9E410 R WM_WINDOWPOSCHANGED S WM_ACTIVATEAPP fActive:True dwThreadID:00000000 R WM_ACTIVATEAPP S WM_NCACTIVATE fActive:True R WM_NCACTIVATE S WM_ACTIVATE fActive:WA_ACTIVE fMinimized:False hwndPrevious:(null) S WM_IME_NOTIFY dwCommand:IMN_OPENSTATUSWINDOW dwCommand:00000002 dwData:00000000 R WM_IME_NOTIFY S WM_SETFOCUS hwndLoseFocus:(null) R WM_SETFOCUS R WM_ACTIVATE S message:0x02CC [Unknown] wParam:00000000 lParam:00C50BA8 R message:0x02CC [Unknown] lResult:00000100 P WM_POINTERENTER wPointerID:0099 wFlags:6017 S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_LBUTTONDOWN R WM_SETCURSOR fHaltProcessing:False P WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:145 yPos:62 R WM_POINTERCAPTURECHANGED P WM_MOUSEMOVE fwKeys:MK_LBUTTON xPos:145 yPos:62 P WM_POINTERLEAVE wPointerID:0099 wFlags:6000 P WM_LBUTTONUP fwKeys:0000 xPos:145 yPos:62 P WM_MOUSEMOVE fwKeys:0000 xPos:145 yPos:62 S WM_CAPTURECHANGED hwndNewCapture:000503F8 R WM_CAPTURECHANGED S WM_CAPTURECHANGED hwndNewCapture:00000000 R WM_CAPTURECHANGED S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE R WM_SETCURSOR fHaltProcessing:False P WM_MOUSEMOVE fwKeys:0000 xPos:145 yPos:62
Click NOT received
S message:0x02CC [Unknown] wParam:00000000 lParam:00AE0BA9 R message:0x02CC [Unknown] lResult:00000100 R WM_POINTERACTIVATE pmsd->lResult:FFFFFFFFFFFFFFFF S WM_MOUSEACTIVATE hwndTopLevel:000503F8 nHittest:HTCLIENT uMsg:WM_POINTERDOWN R WM_MOUSEACTIVATE fuActivate:MA_ACTIVATE S WM_WINDOWPOSCHANGING lpwp:000000E9E3D9E410 R WM_WINDOWPOSCHANGING S WM_WINDOWPOSCHANGED lpwp:000000E9E3D9E410 R WM_WINDOWPOSCHANGED S WM_ACTIVATEAPP fActive:True dwThreadID:00000000 R WM_ACTIVATEAPP S WM_NCACTIVATE fActive:True R WM_NCACTIVATE S WM_ACTIVATE fActive:WA_ACTIVE fMinimized:False hwndPrevious:(null) S WM_IME_NOTIFY dwCommand:IMN_OPENSTATUSWINDOW dwCommand:00000002 dwData:00000000 R WM_IME_NOTIFY S WM_SETFOCUS hwndLoseFocus:(null) R WM_SETFOCUS R WM_ACTIVATE P WM_POINTERENTER wPointerID:0090 wFlags:6017 S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_LBUTTONDOWN R WM_SETCURSOR fHaltProcessing:False P WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:147 yPos:39 R WM_POINTERCAPTURECHANGED S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE R WM_SETCURSOR fHaltProcessing:False P WM_MOUSEMOVE fwKeys:MK_LBUTTON xPos:147 yPos:39 P WM_POINTERLEAVE wPointerID:0090 wFlags:6000 S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_LBUTTONUP R WM_SETCURSOR fHaltProcessing:False P WM_LBUTTONUP fwKeys:0000 xPos:147 yPos:39 S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE R WM_SETCURSOR fHaltProcessing:False P WM_MOUSEMOVE fwKeys:0000 xPos:147 yPos:39 S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE R WM_SETCURSOR fHaltProcessing:False P WM_MOUSEMOVE fwKeys:0000 xPos:147 yPos:39 S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE R WM_SETCURSOR fHaltProcessing:False P WM_MOUSEMOVE fwKeys:0000 xPos:147 yPos:39
On error, additional lines appear
S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_LBUTTONUP R WM_SETCURSOR fHaltProcessing:False
before WM_LBUTTONUP. But I do not know if this is so.
I already tried to debug the .net code to find out which condition causes the Click handler to fail, but I was soon lost in System.Windows.Input.InputManager and the PromoteMainToMouse () function of System.Windows.Input. StylusLogic.
I really don't have enough ideas to check. Therefore, it would be great if someone could give me advice on what else you can check or where to set breakpoints in .net to find the reason. Or even better to find a solution / workaround.
UPDATE:
I found out that I can reproduce this phenomenon also if the mouse pointer is just removed from the application window (at least on our platforms). The probability of an error increases with the complexity of the user interface - my test application does not always recognize a click, but a complex WPF application fails every time.
You should be able to play it using the WPF development studio (e.g. version 2013) on Windows 8.1 with a touch device:
- the developer studio has the ability to open only half of the touch screen.
- move the cursor so that the cursor points to the desktop area
- Touch the button (for example, “start debugging” - the play button): In my case, the first touch never triggers a click event.