none
WPF mouse move

    Question

  • i have an windows service that moves mouse cursor  to a point ,it works for all windows application , i have an WPF Application in fullscreen mode when i run the service and open my wpf app no mouse movement is done instead my mouse cusor is ideal when i try to move the cursor using my mouse it cursor moves  , Why is that
    SK
    Monday, January 04, 2010 11:29 AM

Answers

  • Hello,

    You can't move the mouse cursor in WPF.
    In order to set the mouse position you need to use unmanaged code API. Make a wrapper class like this:

    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);
    }

    And then you can set the mouse position in wpf using:

    MouseOperations.SetCursorPos(54,54);

    Good Luck.
    Monday, January 04, 2010 1:53 PM
  • you can take a look at the testapi library. it has a mousehelper library that you could use.
    Monday, January 04, 2010 2:26 PM

All replies

  • Hello,

    You can't move the mouse cursor in WPF.
    In order to set the mouse position you need to use unmanaged code API. Make a wrapper class like this:

    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);
    }

    And then you can set the mouse position in wpf using:

    MouseOperations.SetCursorPos(54,54);

    Good Luck.
    Monday, January 04, 2010 1:53 PM
  • you can take a look at the testapi library. it has a mousehelper library that you could use.
    Monday, January 04, 2010 2:26 PM