首页  编辑  

判断是否鼠标左右键同时按下

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

using System . Runtime . InteropServices;

[ DllImport ( "user32.dll" )]

public static extern short GetKeyState(int nVirtKey);

public const int VK_LBUTTON = 1 ;

public const int VK_RBUTTON = 2 ;

private void Form1_MouseDown( object sender, MouseEventArgs e)

{

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

               ((GetKeyState(VK_RBUTTON) & 0x80 ) == 0x80 ))

                MessageBox . Show( "Zswang );

}

//or

private void Form1_MouseDown( object sender, MouseEventArgs e)

{

        if (MouseButtons == ( MouseButtons . Left | MouseButtons . Right))

                MessageBox . Show( "Zswang );

}