C#中如何 实现按下键盘上某键实现点击鼠标左键的功能
现在想用WSAD模拟鼠标的上下左右移动,用J和K实现模拟鼠标的左键单击和右键单击。移动已经用if(e.KeyCode==Keys.W){Cursor.Position=n...
现在想用WSAD模拟鼠标的上下左右移动,用 J 和 K 实现模拟鼠标的左键单击和右键单击。
移动已经用
if (e.KeyCode == Keys.W)
{
Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y - 20);
}
实现了, 请问左键单击和右键单击该怎么实现呢? 展开
移动已经用
if (e.KeyCode == Keys.W)
{
Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y - 20);
}
实现了, 请问左键单击和右键单击该怎么实现呢? 展开
1个回答
推荐于2016-01-30 · 知道合伙人互联网行家
关注
展开全部
bool isMouseDown = false;
Point mouseOffset;
先添加全局变量
再添加下面这几个事件
private void TableLrcF_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
}
private void TableLrcF_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOffset = new Point(-e.X, -e.Y);
isMouseDown = true;
}
}
private void TableLrcF_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
Point mouseOffset;
先添加全局变量
再添加下面这几个事件
private void TableLrcF_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
}
private void TableLrcF_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOffset = new Point(-e.X, -e.Y);
isMouseDown = true;
}
}
private void TableLrcF_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询