Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit 19230ae

Browse files
committed
Spurrious mousemove events filtered out
1 parent 5f7852f commit 19230ae

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ScreensaverForm.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,24 @@ public class GlobalUserEventHandler : IMessageFilter
163163
private const int WM_KEYDOWN = 0x100;
164164
private const int WM_KEYUP = 0x101;
165165

166+
// screensavers and especially multi-window apps can get spurrious WM_MOUSEMOVE events
167+
// that don't actually involve any movement (cursor chnages and some mouse driver software
168+
// can generate them, for example) - so we record the actual mouse position and compare against it for actual movement.
169+
private Point? lastMousePos;
170+
166171
public event UserEvent Event;
167172

168173
public bool PreFilterMessage(ref Message m)
169174
{
170-
if ((m.Msg >= WM_MOUSEMOVE && m.Msg <= WM_MBUTTONDBLCLK)
171-
|| m.Msg == WM_KEYDOWN
172-
|| m.Msg == WM_KEYUP)
175+
if ((m.Msg == WM_MOUSEMOVE) && (this.lastMousePos == null))
173176
{
177+
this.lastMousePos = Cursor.Position;
178+
}
179+
180+
if (((m.Msg == WM_MOUSEMOVE) && (Cursor.Position != this.lastMousePos))
181+
|| (m.Msg > WM_MOUSEMOVE && m.Msg <= WM_MBUTTONDBLCLK) || m.Msg == WM_KEYDOWN || m.Msg == WM_KEYUP)
182+
{
183+
174184
if (Event != null)
175185
{
176186
Event();

0 commit comments

Comments
 (0)