0

The reason I'm trying to do this, is that I have a program that when you push one of the buttons it records where your mouse was at the time, and then if you push another it moves your mouse to that location. If there is any simpler way to do this please tell me.

svick
  • 236,525
  • 50
  • 385
  • 514
zimooo2
  • 421
  • 1
  • 4
  • 9

1 Answers1

2

I'm going to make some assumptions since I am missing some of the context into what you are trying to accomplish:

  • When you press the '0' key on the numpad you will grab the mouse coordinates
  • When you press the '1' key on the numpad you will move the mouse.

That being said, you can accomplish what you are trying to do with the following code:

private void YourControl_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    if (e.KeyCode == Keys.NumPad0) 
    {
       //Grab mouse coordinates
    }
    if (e.KeyCode == Keys.NumPad1) 
    {
       //Code to move the mouse
    }
}

Of course, this only works if your application is in focus, if you want to accomplish this when you application is minimized you will have to register global hotkeys.

If you would like more details that are specific to your particular problem, please edit you question to include more specific information and I will do my best to help you out.

Community
  • 1
  • 1
Robert Greiner
  • 29,049
  • 9
  • 65
  • 85