Forcing mouse movement along a specific axis in WPF

How can I make the mouse move along a certain axis while the user holds the left button down? I would like the user to be able to move the mouse along the x-axis, while any movement along the y-axis would be β€œcanceled”.

thanks eden

+3
source share
1 answer

Check this out: 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 will need to call the method from the Mouse.MouseMove event handler .

MouseOperations.SetCursorPos(xAxisPosition,0);
+1
source

Source: https://habr.com/ru/post/1750637/


All Articles