Jump to content

C# for Mouse Commands

- - - - -

  • Please log in to reply
3 replies to this topic

#1
McGol

McGol

    Newbie

  • Members
  • Pip
  • 2 posts
Hello Everyone! I am a bit new to C# programming and none of the 4 books I have or two on WPF can help me with my latest puzzle, so perhaps someone in the community can help me.

I need some assistance on how to get C# to change the location of the mouse, Lft/Mid/Rght click and scroll (just for thoroughness, might as well get it all for the future).

First, I need to know what the proper using statement(s) should be (currently using using System.Runtime.InteropServices; ).

The using statement is needed so that I can use “GetCursorPos()” and “SetCursorPosition()”

Second, I've created a Point: "Point MyPoint = new Point(100, 100);", but when I send "MyPoint" as an argument to SetCursorPosition and my method, the compiler says it only takes one argument. The method is

"public void PointerMove(Point ChangePosition)"

And of course, this was supposed to be the easy part. I haven’t even gotten into clicking yet. 8[


:confused:

#2
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts
According to msdn the only setcursorPosition function I can find is related to the console cursor and not the mouse cursor.

To control the mouse cursor properties you have the following class: Cursor Class (System.Windows.Forms)

And for an example of moving the cursor you can check: Cursor.Position Property (System.Windows.Forms)

#3
McGol

McGol

    Newbie

  • Members
  • Pip
  • 2 posts
Thanks for the nudge in the right direction. Yes, the Console.SetCursorPosition command was the only one I came across, which is not what I wanted. As I did some research, I started questioning whether "Cursor" related commands were what I needed in any regard.

So, are Cursor methods the only way to move the mouse? Or is there a separate Mouse method that I'm unaware of?

And thanks again for the help, I'm at my wits end.

====
Update: Digging around, I found MouseEventArgs

Update 2: ... And that got it. The MouseEventArgs tell you about the mouse (whether there was a click/scroll/movement and its location), the Cursor commands in System.Windows.Forms are needed to actually move it.

Thanks Very Much! A little nudge can go a long way! :thumbup1:

Edited by McGol, 11 July 2011 - 08:13 PM.


#4
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts
Glad you figured it out ;)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users