views:

25

answers:

1

Hi,

How can I force the mouse to move along a specific axis while the user keeps the left button down? I would like the user to be able to move the mouse along the X axis while any movement on the Y axis would be "canceled".

thanks Eden

+1  A: 

Check this: http://social.msdn.microsoft.com/Forums/en/wpf/thread/9b07abce-bb32-4cd1-9ae5-d34973d5cc95

From the link:

public partial class MouseOperations 
{ 
    [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SetCursorPos")]   
    [return:System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]    
    public static extern bool SetCursorPos(int X, int Y); 
} 

You'll have to call the method from the Mouse.MouseMove event handler.

MouseOperations.SetCursorPos(xAxisPosition,0);
Veer