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

本文介绍了如何利用Autohotkey(AHK)实现一个简单的全局鼠标手势功能,以提高电脑操作效率。通过AHK代码,识别八个方向的鼠标手势,分别对应不同的快捷操作,如删除、恢复、最大化窗口等。这一功能旨在减少键盘和鼠标间频繁切换,提升用户体验。


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

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




评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值