Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouse.Synchronize()

Tags:

c#

.net

What does Mouse.Synchronize() do in .Net?

MSDN says it 'forces the mouse to resynchronize'

like image 368
NVM Avatar asked Mar 30 '11 05:03

NVM


2 Answers

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.

like image 90
jing Avatar answered Oct 26 '22 15:10

jing


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.

like image 29
Shadow Wizard Hates Omicron Avatar answered Oct 26 '22 15:10

Shadow Wizard Hates Omicron