C#如何在keydown事件里判断按下的是左shift还是右shift

来源:学生作业帮助网 编辑:作业帮 时间:2024/07/26 22:30:28
C#如何在keydown事件里判断按下的是左shift还是右shift
xUKK@+ )HzЇJQ/7Iim*҂'G)^ă&/tc1B/1ov&Q+w R]ù~kvϺsx:.;7mVDyrUEs41+YZ圉tO(G)njIu҄TWّv$W5ơfʘí+ F:05eE(W6˄G ԤjġU~-lk^:%D!uнB1q āY[X0*2Ԭ wb`(WI4|Lb?PV.cZ*j@*Y

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");
            }
        }
    }