在平时用电脑的过程中,我喜欢隔段时间就把鼠标左右调换一下
当然,自从我给电脑同时接上左右两只鼠标以后,来回调换鼠标是避
1. SwapMouseButton
根据MSDN所述,可以通过调用SwapMouseButton
BOOL SwapMouseButton(
BOOL fSwap
);
我们可以在.NET工程中通过P/Invoke轻松声明对该API的调用。我写的调用声明如下:
// P/Invoke declarations
[DllImport("user32.dll")]
private extern static bool SwapMouseButton(bool fSwap);
其中,fSwap是唯一需要传入的参数,当它的值为true时
2. SystemParametersInfo
除了调用SwapMouseButton来实现鼠标左右值功能切
BOOL SystemParametersInfo(
UINT uiAction,
UINT uiParam,
PVOID pvParam,
UINT fWinIni
);
用C#可以进行如下声明:
[DllImport("user32.dll")]
private extern static int SystemParametersInfo(uint uiAction, uint
uiParam, IntPtr pvParam, uint fWinIni);
其中,uiAction指定一个需要获取的系统参数,如屏幕大小
由此,我们需要在uiAction位置传入SPI
#define SPI_SETMOUSEBUTTONSWAP 33
可见,SPI_SETMOUSEBUTTONSWAP定义的是整
private const uint SPI_SETMOUSEBUTTONSWAP = 33;
通过上述两种方法,我们都可以轻松地实现鼠标功能切换了。不过
根据MSDN,GetSystemMetrics的原型是:
int GetSystemMetrics(
int nIndex
);
其中nIndex参数有SM_SWAPBUTTON值可选,SM
#define SM_SWAPBUTTON 23
我们可以在C#中如此定义SM_SWAPBUTTON:
private const int SM_SWAPBUTTON = 23;
声明GetSystemMetrics:
[DllImport("user32.dll")]
private extern static int GetSystemMetrics(int nIndex); // Updated 04.10.22. Many thanks to JGTM'2004 [MVP]
当GetSystemMetrics返回0时,表明当前系统鼠标
OK,把上述几点连起来,就可以轻松写成一个能快速切换鼠标功能
打印 | 张贴于 2004-10-21 16:07:00 | Tag:暂无标签
留言反馈
[url=http://www.mmosgames.com]runescape money[/url]
我提点建议,再进一步,不用点什么图标了,动哪只mouse,就使用哪只mouse的设置。这样最简单好用了。
pooronce@msn.com
jxh047000@utdallas.edu
Thanks very much.
有同感啊,我也是这么办的,可惜我的笔记本在控制面板上不支持usb口的左右切换,只有一个ps/2口,这个程序太及时了
多谢提醒!是我写的时候马虎了,刚刚改过。nIndex, nIndex, nIndex, nIndex...
当然解决办法也不一定是换用左手鼠标——这只是诸多解决方法之一,最常用的其实就是隔段时间站起来活动活动,让自己的身体refresh一下。IT人更要关爱自己的健康嘛。:)
希望我们每个人都健健康康的!
而且用不惯左手鼠标
using System.Runtime.InteropServices; 声明