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

Commit

Permalink
Spurrious mousemove events filtered out
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkWhybird committed Nov 17, 2017
1 parent 5f7852f commit 19230ae
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ScreensaverForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,24 @@ public class GlobalUserEventHandler : IMessageFilter
private const int WM_KEYDOWN = 0x100;
private const int WM_KEYUP = 0x101;

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

public event UserEvent Event;

public bool PreFilterMessage(ref Message m)
{
if ((m.Msg >= WM_MOUSEMOVE && m.Msg <= WM_MBUTTONDBLCLK)
|| m.Msg == WM_KEYDOWN
|| m.Msg == WM_KEYUP)
if ((m.Msg == WM_MOUSEMOVE) && (this.lastMousePos == null))
{
this.lastMousePos = Cursor.Position;
}

if (((m.Msg == WM_MOUSEMOVE) && (Cursor.Position != this.lastMousePos))
|| (m.Msg > WM_MOUSEMOVE && m.Msg <= WM_MBUTTONDBLCLK) || m.Msg == WM_KEYDOWN || m.Msg == WM_KEYUP)
{

if (Event != null)
{
Event();
Expand Down

0 comments on commit 19230ae

Please sign in to comment.