-1

I using User32.dll, running the application,pressing buttons getting information.

My problem is when i pull some data ,but when i move my mouse over spesific element it can stop this process ,sow i need to move my mouse to safe place and make it stay there for 2sec.

I found the way to move it to safe place

Cursor.Position = new System.Drawing.Point(3000, 0);

But how i make it stay there/stop moving for 2sec..

Vladimir Potapov
  • 2,347
  • 7
  • 44
  • 71
  • 4
    If the user moving his mouse over some element is causing your data pull to stop, you may want to think about changing your design. For example, atomically setting a variable while the data pull is happening so that you ignore the mouseover event while it is happening. – merlin2011 May 19 '14 at 07:19
  • 9
    The mouse isn't *yours*, it's the *users*. You should not be trying to treat a global resource as something that belongs to your program. – Damien_The_Unbeliever May 19 '14 at 07:19
  • While it is certainly possible to force the mouse to stay in a particular position for 2 seconds (worse case you can just keep using your line above every 5 ms for 2 seconds), that might annoy the user. – merlin2011 May 19 '14 at 07:20
  • I using User32.dll to run application(not my app),inserting User/password and then pull some data,why the mouseover breaks it i dont know it look very strange to me too,but i can't do nothink,i don't have API i can use only PostMessage/SendMessage. – Vladimir Potapov May 19 '14 at 07:23
  • "that might annoy the use" No my program starts every 12 hours and pull information by it self, user do not see this,but if suddenly the mouse is in wrong position it will stop the process – Vladimir Potapov May 19 '14 at 07:27
  • Elaborate that more. What exactly breaks your process? Mouse movement occurs via interrupts. So depending on what breaks your processing forcing a mouse to a certain position may break your process too. (Besides that what ever you try looks inefficient or shady) – Samuel May 19 '14 at 08:09
  • Sounds like the old [xy problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) to me. – Steve Pettifer May 19 '14 at 08:53
  • 1
    They don't know the answer because the question doesn't make sense. They are still trying to help you, though, because that's what we do here. – Cody Gray - on strike May 19 '14 at 13:10

1 Answers1

1

Well you could make a timer that loops this code: Cursor.Position = new System.Drawing.Point(3000, 0);

But that would be inefficient. So I suggest Making your form implement IMessageFilter.

Then add the following code to the form:

Rectangle BoundRect;
Rectangle OldRect = Rectangle.Empty;

private void EnableMouse()
{
    Cursor.Clip = OldRect;
    Cursor.Show();
    Application.RemoveMessageFilter(this);
}
public bool PreFilterMessage(ref Message m)
{
    if (m.Msg == 0x201 || m.Msg == 0x202 || m.Msg == 0x203) return true;
    if (m.Msg == 0x204 || m.Msg == 0x205 || m.Msg == 0x206) return true;
    return false;
}
private void DisableMouse()
{
    OldRect = Cursor.Clip;
    // Arbitrary location.
    BoundRect = new Rectangle(50, 50, 1, 1); 
    Cursor.Clip = BoundRect;
    Cursor.Hide();
    Application.AddMessageFilter(this);
}  

This will hide the cursor making it unable to move it and disable the right and left mousebuttons.

Stijn Bernards
  • 1,091
  • 11
  • 29