What does Mouse.Synchronize() do in .Net?
MSDN says it 'forces the mouse to resynchronize'
Just my assumption:
Similar method exists in Stylus class: Stylus.Synchronize. It should be used together with Stylus.DirectlyOver to ensure that stylus pointer is still above button, although the button was moved somewhere else.
I believe that "Synchronize" is implemented in parent class of both classes: Stylus and Mouse. It's important for Stylus, but it's not necessary for the Mouse. I tried example from Stylus.Synchronize ( I just replaced "Stylus" by "Mouse" ) and it works well also without Mouse.Synchronize(); line.
Well, for what it's worth here is the source code of the method:
public void Synchronize()
{
PresentationSource criticalActiveSource = this.CriticalActiveSource;
if (((criticalActiveSource != null) && (criticalActiveSource.CompositionTarget != null)) && !criticalActiveSource.CompositionTarget.IsDisposed)
{
InputReportEventArgs args;
int tickCount = Environment.TickCount;
Point clientPosition = this.GetClientPosition();
RawMouseInputReport report = new RawMouseInputReport(InputMode.Foreground, tickCount, criticalActiveSource, RawMouseActions.AbsoluteMove, (int) clientPosition.X, (int) clientPosition.Y, 0, IntPtr.Zero);
report._isSynchronize = true;
if (this._stylusDevice != null)
{
args = new InputReportEventArgs(this._stylusDevice, report);
}
else
{
args = new InputReportEventArgs(this, report);
}
args.RoutedEvent = InputManager.PreviewInputReportEvent;
this._inputManager.Value.ProcessInput(args);
}
}
The important line is:
RawMouseInputReport report = new RawMouseInputReport(InputMode.Foreground, tickCount, criticalActiveSource, RawMouseActions.AbsoluteMove, (int) clientPosition.X, (int) clientPosition.Y, 0, IntPtr.Zero);
According to this, the method is trying to move the mouse to the same position it's already in then analyze the results - here comes my own assumption, that if there's any offset between the previous position and new position, it's stored somewhere and used for any future mouse actions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With