我想创建一个按W
,A
,S
,D
键移动光标的程序。我创建了一个表单,因为很难将Keyboard.IsKeyDown(Key.W)
放在脚本中。
这是我到目前为止的代码:
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);
}
}
}
}
然而,它会抛出此错误
会员' Cursor.Position'无法使用实例访问 参考;使用类型名称来限定它
我该如何解决这个问题?任何帮助表示赞赏。
答案 0 :(得分:1)
您的代码所在的Form
具有Cursor
属性。这不是您想要访问的内容。
相反,完全限定类型,如错误所示:
System.Windows.Forms.Cursor.Position