切换鼠标左右按键引发的思考(批处理、VBS、DynamicWrapper)
2012-03-21 22:10
495 查看
背景:笔记本有触摸板,老是碰到,经常不小心搞成关闭、撤销等等不想要的操作。于是就安装了触摸版的专用驱动,以便按Fn进行关闭。
问题:最近又喜欢使用左手,结果安装了这个触摸板的驱动,硬是找不到设置鼠标的“切换主次按钮”。咨询官方的回答是“非得卸载掉驱动才行”(不知道这是不是BUG),让人情何以堪。
正常应对:1、换回右手习惯,万事无忧。2、卸载驱动,万事大吉
换位:如果不想呢?是不是有其他方法可以解决?
1、发现修改注册表,结果是必须注销才能够实现更换。
2、使用EXCEL建立宏,使用Windows API直接调用代码:
这样的话,每次换鼠标点击一下就可以了,也挺方便的。
问题又发生了,这个触摸板的驱动,每次开机启动的时候,会自动更换成右手习惯,并且且使用功能键Fn+F6禁用后,仍然会自动启用。。。
于是就想起了开机启动,然后调用Fn+F6键。而由于笔记本的Fn键实现是非常困难的,所以调用功能键禁用触摸板的想法直接放弃,只保留了开机启动功能。
这样就简单了,使用啥语言编写一个简单的EXE(调用User32.dll里面的SwapMouseButton函数),开机调用就OK了。
为图省事,直接启动项里添加了快捷方式,结果。。。切换鼠标左右按键在加载触摸板驱动之前被调用,效果没有达到。
直接在简单的EXE里面判断一下触摸板驱动(相应进程存在)加载了就可以了,偶喜欢折腾,还是直接写个批处理吧。
Bat代码
@echo off
title 启动左右键切换程序
set var = 0
:continue
tasklist|find /i "XXXX.exe"
if %errorlevel% == 0 goto yes
set /a var+=1
ping localhost -n 5 > nul
if %var% lss 10 goto continue
:yes
SwapMouse.exe
:no
exit
保存为批处理脚本,搞定!
到这里基本算完成任务了,但是每次启动有一个CMD窗口,看着也不太好,可以使用VBS脚本来替换。只是正常情况下,VBS只能够调用COM组合,直接调用User32.dll并不能够完成任务,还好有人已经写了一个DynaWrap.dll(需要先注册一下regsvr32 DynaWrap.dll,相应的打包RAR,见我的下载)的OCX控件能够帮我们完成相应的功能。
Vbs代码
Sub WaitProcess(sProcessName)
dim intTimes
intTimes = 0
do while intTimes < 5
For each Process in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_process") '利用wmi
遍历所有进程
If uCase(Process.Name) = uCase(sProcessName) Then '判断进程名称
Dim UserWarp
Set UserWarp =CreateObject("DynamicWrapper")
UserWarp.Register "User32.Dll", "SwapMouseButton", "I=l", "f=S","R=l"
UserWarp.SwapMouseButton(0)
exit do
End If
Next
intTimes =intTimes + 1
Wscript.sleep 1000
loop
End Sub
比如要等等XXX进程,可以
WaitProcess "APoint.exe"
保存为.vbs脚本,然后添加到启动项,算一个结束了。
相关文件下载,参照http://smartyidiot.iteye.com/blog/1460949
问题:最近又喜欢使用左手,结果安装了这个触摸板的驱动,硬是找不到设置鼠标的“切换主次按钮”。咨询官方的回答是“非得卸载掉驱动才行”(不知道这是不是BUG),让人情何以堪。
正常应对:1、换回右手习惯,万事无忧。2、卸载驱动,万事大吉
换位:如果不想呢?是不是有其他方法可以解决?
1、发现修改注册表,结果是必须注销才能够实现更换。
2、使用EXCEL建立宏,使用Windows API直接调用代码:
Private Declare Function SwapMouseButton Lib "user32" (ByVal bSwap As Long) As Long Private Sub Command1_Click() SwapMouseButton (1) ' 1-->右手 0-->左手 End Sub
这样的话,每次换鼠标点击一下就可以了,也挺方便的。
问题又发生了,这个触摸板的驱动,每次开机启动的时候,会自动更换成右手习惯,并且且使用功能键Fn+F6禁用后,仍然会自动启用。。。
于是就想起了开机启动,然后调用Fn+F6键。而由于笔记本的Fn键实现是非常困难的,所以调用功能键禁用触摸板的想法直接放弃,只保留了开机启动功能。
这样就简单了,使用啥语言编写一个简单的EXE(调用User32.dll里面的SwapMouseButton函数),开机调用就OK了。
为图省事,直接启动项里添加了快捷方式,结果。。。切换鼠标左右按键在加载触摸板驱动之前被调用,效果没有达到。
直接在简单的EXE里面判断一下触摸板驱动(相应进程存在)加载了就可以了,偶喜欢折腾,还是直接写个批处理吧。
Bat代码
@echo off
title 启动左右键切换程序
set var = 0
:continue
tasklist|find /i "XXXX.exe"
if %errorlevel% == 0 goto yes
set /a var+=1
ping localhost -n 5 > nul
if %var% lss 10 goto continue
:yes
SwapMouse.exe
:no
exit
@echo off title 启动左右键切换程序 set var = 0 :continue tasklist|find /i "XXXX.exe" if %errorlevel% == 0 goto yes set /a var+=1 ping localhost -n 5 > nul if %var% lss 10 goto continue :yes SwapMouse.exe :no exit
保存为批处理脚本,搞定!
到这里基本算完成任务了,但是每次启动有一个CMD窗口,看着也不太好,可以使用VBS脚本来替换。只是正常情况下,VBS只能够调用COM组合,直接调用User32.dll并不能够完成任务,还好有人已经写了一个DynaWrap.dll(需要先注册一下regsvr32 DynaWrap.dll,相应的打包RAR,见我的下载)的OCX控件能够帮我们完成相应的功能。
Vbs代码
Sub WaitProcess(sProcessName)
dim intTimes
intTimes = 0
do while intTimes < 5
For each Process in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_process") '利用wmi
遍历所有进程
If uCase(Process.Name) = uCase(sProcessName) Then '判断进程名称
Dim UserWarp
Set UserWarp =CreateObject("DynamicWrapper")
UserWarp.Register "User32.Dll", "SwapMouseButton", "I=l", "f=S","R=l"
UserWarp.SwapMouseButton(0)
exit do
End If
Next
intTimes =intTimes + 1
Wscript.sleep 1000
loop
End Sub
比如要等等XXX进程,可以
WaitProcess "APoint.exe"
Sub WaitProcess(sProcessName) dim intTimes intTimes = 0 do while intTimes < 5 For each Process in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_process") '利用wmi 遍历所有进程 If uCase(Process.Name) = uCase(sProcessName) Then '判断进程名称 Dim UserWarp Set UserWarp =CreateObject("DynamicWrapper") UserWarp.Register "User32.Dll", "SwapMouseButton", "I=l", "f=S","R=l" UserWarp.SwapMouseButton(0) exit do End If Next intTimes =intTimes + 1 Wscript.sleep 1000 loop End Sub '比如要等等XXX进程,可以 WaitProcess "APoint.exe"
保存为.vbs脚本,然后添加到启动项,算一个结束了。
相关文件下载,参照http://smartyidiot.iteye.com/blog/1460949
相关文章推荐
- [Delphi]切换鼠标左右按键
- 修改系统鼠标左右按键快速切换
- 在自己App中处理硬件按键(左右软键,拨号键等)
- 由APUE中的错误处理函数err_xxx引发的思考
- 自动播放,鼠标触发排序切换JS焦点轮播图(不带左右箭头切换)
- JS+CSS控制左右切换鼠标可控的无缝图片滚动代码
- js鼠标点击按钮切换图片-图片自动切换-点击左右按钮切换特效代码
- 鼠标点击按钮图片切换+自动切换+左右按钮点击切换效果
- 使用jQuery实现鼠标点击左右按钮滑动切换
- iMouse - 快速切换鼠标左右键
- SwapMouseButton切换鼠标左右键
- ReportViewer 2010 打印预览,用鼠标快速切换显示比例时报错:存储空间不足,不能处理此命令
- 网页屏蔽鼠标左右键和键盘按键功能
- QT事件处理,鼠标事件,按键键盘事件,定时器,进度条。
- cocos2d-x 处理windows按键消息 鼠标移动消息
- 左右切换鼠标可控的无缝图片滚动代码
- android 横竖屏切换引发的几点思考
- 一个J2ME的应用移植到BlackBerry上,如何处理按键响应(以及如何映射左右软键)
- C#切换鼠标左右键习惯