C#如何在keydown事件里判断按下的是左shift还是右shift
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 11:50:35
C#如何在keydown事件里判断按下的是左shift还是右shift
C#如何在keydown事件里判断按下的是左shift还是右shift
C#如何在keydown事件里判断按下的是左shift还是右shift
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern short GetAsyncKeyState(Keys vKey);
public Form1()
{
InitializeComponent();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.ShiftKey)
{
if (Convert.ToBoolean(GetAsyncKeyState(Keys.LShiftKey)))
MessageBox.Show("Left");
if (Convert.ToBoolean(GetAsyncKeyState(Keys.RShiftKey)))
MessageBox.Show("Right");
}
}
}