1

I've wanted to create a program that moves the cursor by pressing the W,A,S,D keys. I created a form because it was difficult to put the Keyboard.IsKeyDown(Key.W) in the script.

This is the code I have so far:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;

namespace keyboardMouse
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void rdnbtnMove_CheckedChanged(object sender, EventArgs e)
        {
            if (Keyboard.IsKeyDown(Key.W))
            {
                    Cursor.Position = new System.Drawing.Point(      
                        Cursor.Position.Y + 5);
            }
        }
    }
}

However, it throws this error

Member 'Cursor.Position' cannot be accessed with an instance reference; qualify it with a type name instead

How can I fix this? Any help is appreciated.

William Barbosa
  • 4,936
  • 2
  • 19
  • 37
slumpyrat
  • 66
  • 2
  • 7

1 Answers1

2

the Form your code is on has a Cursor property. That's not what you want to access.

Instead fully qualify the type, as the error indicates:

System.Windows.Forms.Cursor.Position
Sam Axe
  • 33,313
  • 9
  • 55
  • 89