首页  编辑  

判断是否方向左右键同时按下

Tags: /C#/界面处理/   Date Created:

using System . Runtime . InteropServices;

[ DllImport ( "user32.dll" )]

public static extern short GetKeyState( int nVirtKey);

public const int VK_LEFT = 37 ;

public const int VK_UP = 38 ;

public const int VK_RIGHT = 39 ;

public const int VK_DOWN = 40 ;

private void Form1_KeyDown( object sender , KeyEventArgs e)

{

    switch (e . KeyCode)

   {

        case Keys . Left:

        case Keys . Right:

        case Keys . Down:

        case Keys . Up:

            if (((GetKeyState(VK_RIGHT) & 0x80 ) == 0x80 ) &&

               ((GetKeyState(VK_DOWN) & 0x80 ) == 0x80 ))

                MessageBox . Show( "Zswang );

            break ;

   }

}