开发者

How can i detect if the mouse is moving both within and out of the bounds of my window in WPF/C#?

开发者 https://www.devze.com 2023-03-24 04:31 出处:网络
I have a small video app that i would like to give vlc-like functionality. By that, I mean having a certain element disappear and appear on mouse move or mouse not moving. I have a rough concept of ho

I have a small video app that i would like to give vlc-like functionality. By that, I mean having a certain element disappear and appear on mouse move or mouse not moving. I have a rough concept of how to do this bu开发者_C百科t I have no ideea how i coul detect if the mouse is moving or not. I thought about using the GetPosition function but that will just give me the mouse's position and won't let me know if the cursor is moving or not. I would like to use a timer to count down 2-3 seconds after the mouse has stopped moving and then either fade out the control or just make it collapse without further ado. I can't check the value of the position variable every milisecond. Is there some other way to do this ?


You can use a hook functionality so you will be notified when a mouse move, I use to use this free opensource library.

How to use it:

using Gma.UserActivityMonitor.GlobalEventProvider;

GlobalEventProvider _globalEventProvider1 
                                 = new Gma.UserActivityMonitor.GlobalEventProvider();

this.globalEventProvider1.MouseMove += HookMouseMove;//to listen to mouse move


Capture the mouse. Release the capture if the user actually clicks anywhere else. Then you can use the standard WPF mouse move event.

myElement.MouseMove += (my MouseMove handler)
Mouse.Capture(myElement);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号