0%

C# 获取鼠标按键数量

1
2
3
4
5
//引入DLL函数

[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]

public extern static int GetSystemMetrics(int intcount);

完整代码,创建一个窗体拖入一个文本框控件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public const int SM_CMOUSEBUTTONS = 43;//定义一个常量值

[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]

public extern static int GetSystemMetrics(int intcount);

public Form1()
{
InitializeComponent();
}



private void Form1_Load(object sender, EventArgs e)
{
int jishu = GetSystemMetrics(SM_CMOUSEBUTTONS); //获取鼠标按键数
textBox1.Text = Convert.ToString(jishu);
}
觉得文章有用?请我喝杯咖啡~