使用Autohotkey 实现简单的全局鼠标手势功能

来源:互联网 发布:c语言标准库函数有哪些 编辑:程序博客网 时间:2024/05/20 11:24


为什么需要一个全局的鼠标手势

一个趁手的鼠标手势可以减少键盘与鼠标键的切换,大大提高电脑操作的流畅性。鼠标手势,大家都不陌生,很多人在安装了网页浏览器之后的第一件事就是安装一个鼠标手势扩展,可见鼠标手势这个功能是会让人上瘾的。我也有很长一段时间使用网页中鼠标手势功能。使用下来发现,自己只会使用众多手势中的一两个,而其他的手势功能会由于在日常使用中不常见而慢慢生疏、淡忘。由此,自己想用AHK实现一个全局的鼠标手势功能,让所有的功能都用起来。

网上有很多使用AHK实现鼠标手势的方法,但是自己还是弄了一个足够简单的。可以实现八个方向的鼠标手势识别。八个方向对应八个功能,足够用了。

AHK 代码

; 鼠标手势rbutton::      minGap  = 30 ; 设定的识别阈值,大于此阈值,说明在某方向上有移动  mousegetpos xpos1,ypos1  Keywait, RButton, U  mousegetpos xpos2, ypos2  if (abs(xpos1-xpos2) < minGap and abs(ypos1-ypos2)<minGap) ; nothing 没有运动,直接输出rbutton   send, {rbutton}  else if (xpos1-xpos2 > minGap and abs(ypos1-ypos2)<minGap) ; left  delete(对于文件或选定的字符有效)   send, {delete}  else if (xpos2-xpos1 > minGap and abs(ypos1-ypos2)<minGap) ; right ctrl+z 恢复     send, ^z  else if (abs(xpos1-xpos2)< minGap and (ypos1-ypos2)>minGap) ; up 最大化窗口, win+up    send, #{up}  else if (abs(xpos1-xpos2)< minGap and (ypos2-ypos1)>minGap) ; down 显示桌面, win+d    send, #d  else if (ypos2-ypos1 > minGap and (xpos1-xpos2) > minGap) ; down and left , ctrl+shift+T    send, ^+t  else if (ypos2-ypos1 > minGap and (xpos2-xpos1) > minGap) ; down and right, ctrl+w    send, ^w  else if (ypos1-ypos2 > minGap and (xpos2-xpos1) > minGap) ; up and right alt+f4   send, !{F4}  else if (ypos1-ypos2 > minGap and (xpos1-xpos2) > minGap) ; up and left nothing   send, {rbutton}  else      send, {rbutton}  return

AHK 实现原理

识别右键按下时的鼠标位置,以及抬起鼠标右键时的位置。当X(水平)、Y(垂直)方向大于一定像素阈值(这里设定为30)时,判断在此方向上有移动。当X、Y方向都小于此阈值时,判断没有移动,发出默认的『鼠标右键』。

全局手势功能

运行ahk程序之后,可以实现八个方向的鼠标手势。八个方向的功能如图所示。




0 0
原创粉丝点击