实现效果:
知识运用:
API函数SwapMouseButton //决定是否要交换鼠标左右键的功能
//bSwap :如果为非零 则交换 否则恢复正常状态
//返回值: 非零则表明已经交换 否则返回零
[DllImport("user32.dll", EntryPoint = "SwapMouseButton")] public extern static int SwapMouseButton(int bSwap);
实现代码:
[DllImport("user32.dll", EntryPoint = "SwapMouseButton")] public extern static int SwapMouseButton(int bSwap); public void DefaultRightButton() { SwapMouseButton(1); //改为鼠标右键 } public void DefaultLeftButton() { SwapMouseButton(0); //恢复左键 } private void button1_Click(object sender, EventArgs e) { this.DefaultRightButton(); //交换按键 } private void button2_Click(object sender, EventArgs e) { this.DefaultLeftButton(); //恢复默认 }