0

Okay so there are plenty of samples for mouse global hooking.

My issue is how can I add a timer/delay for mouse movement.

What is the way of doing this? I thought maybe I should Thread.Sleep() on detecting WM_MOUSEMOVE ?

if (MouseMessages.WM_MOUSEMOVE == (MouseMessages)wParam)
   {
     Thread.Sleep(delay)
   }

Thanks.

ADyson
  • 57,178
  • 14
  • 51
  • 63
normaluser
  • 57
  • 2
  • 7
  • 1
    What action you want to delay? How do you use this hook? If you tell us X from [XY problem](https://meta.stackexchange.com/q/66377/299295) there might be a better solution. – Sinatr Sep 18 '20 at 12:27
  • As I said I want to delay the "Mouse Movement". All I need to do is add a time delay to it. – normaluser Sep 18 '20 at 12:32

1 Answers1

1

i'm afraid you cannot slow down the mouse movement in this way. Here you are just notified of a new mouse position, the system doesn't care what you do with this notification and how long it takes to complete, or if it sleeps.

I suppose you should "record" the mouse position every "delay" time, and then every time a new WM_MOUSEMOVE event arrives (and the coordinates are different from the record ones), then you should "reset" the mouse cursor position to the saved coordinates.

of course, this until the WM_MOUSEMOVE arrives within "delay" time. Otherwise just record a new position and wait for the next event.

.NET have the Cursor.Position property that should allow you to move the mouse cursor where you want, other languages should have their analogous, but i've never tried it and i'm not sure it operates correctly in your "global" context.

anyway messing around with the cursor position is something that can make the user very upset

maybe you don't want to stop completely the cursor for "delay" time, maybe you want to linear interpolate the new position with the previous one with a <1 factor? this will slow down the mouse but with a smoother effect.

Mosè Bottacini
  • 4,016
  • 2
  • 24
  • 28
  • Cursor.Position is not actually moving the mouse position to the specified coordinates. I tried it what I got is another mouse icon that appears and disappears at the other position in fast manners. – normaluser Sep 18 '20 at 14:15
  • strange, it moves correctly for me, as i said it may not work in your "global" context, you should try with SetCursorPos from user32.dll https://www.pinvoke.net/default.aspx/user32/SetCursorPos.html i'm afraid that after you use Cursor.Position another event arrives and moves it again, anyway the fact that you see two cursors is the prove that the cursor is moving, but so fat that they appear to be two – Mosè Bottacini Sep 18 '20 at 14:22
  • Hello sorry for late reply, yeah same for SetCurorPos it does not work as supposed in global context. It's like on mouse move event it sets cursor position to location I put and instantly goes back to where it is as you said and that's why they appear to be two. Any other suggestions you have? – normaluser Sep 24 '20 at 07:55
  • I don't think you can do much more than this with the system cursor. Maybe you could hide the cursor and display a full screen overlay with your own mouse cursor which you can control completely. Not easy task to accomplish anyway. But... what's the purpose of all of this, if I can ask? – Mosè Bottacini Sep 25 '20 at 17:46