干货 Tips Rules & Tips
1. 遵守中国大陆相关法律法规
2. 本版还在调整当中

鼠标选中复制,中键粘贴脚本

查看: 5243|回复: 11
1
执黑敌夜 发表于 2017-6-11 23:24:16
本帖最后由 虫子 于 2017-6-12 01:39 编辑

发现附件发不了,只好将 ahk 的脚本发上来分享,大家安装完神器 ahk(https://autohotkey.com/

之后将以下脚本保存为后缀名 ahk 的文件,放于 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup,这样开机启动就完成啦。

之所以有这个脚本是学习英语复制粘贴太烦,便去ahk论坛凑了这么个脚本,比什么exe靠谱多了。自己还做了关联mdict的热键启动exe,通过surface的蓝牙笔,选中单词,点击笔帽自动调用粘贴板弹出字典。这个体验完美!需要的话就提供vs源码让大家自行封装exe哈。(ps:也做过关联edge 的搜索,类似一键谷歌功能,发现因为自己的技术,失灵时不灵。放弃)

  1. ;Auto copy clipboard
  2. ~Lshift::
  3. TimeButtonDown = %A_TickCount%
  4. ; Wait for it to be released
  5. Loop
  6. {
  7.    Sleep 10
  8.    GetKeyState, LshiftState, Lshift, P
  9.    if LshiftState = U  ; Button has been released.
  10.       break
  11.    elapsed = %A_TickCount%
  12.    elapsed -= %TimeButtonDown%
  13.    if elapsed > 200  ; Button was held down long enough
  14.    {
  15.       x0 = A_CaretX
  16.       y0 = A_CaretY
  17.       Loop
  18.    {
  19.      Sleep 20                    ; yield time to others
  20.      GetKeyState keystate, Lshift
  21.      IfEqual keystate, U, {
  22.        x = A_CaretX
  23.        y = A_CaretY
  24.        break
  25.      }
  26.    }
  27.    if (x-x0 > 5 or x-x0 < -5 or y-y0 > 5 or y-y0 < -5)
  28.    {                             ; Caret has moved
  29.       clip0 := ClipBoardAll      ; save old clipboard
  30.       ;ClipBoard =
  31.       Send ^c                    ; selection -> clipboard
  32.       ClipWait 1, 1              ; restore clipboard if no data
  33.       IfEqual ClipBoard,, SetEnv ClipBoard, %clip0%
  34.    }
  35.       return
  36.    }
  37. }
  38. ~LButton::
  39. MouseGetPos, xx
  40. TimeButtonDown = %A_TickCount%
  41. ; Wait for it to be released
  42. Loop
  43. {
  44.    Sleep 10
  45.    GetKeyState, LButtonState, LButton, P
  46.    if LButtonState = U  ; Button has been released.
  47.    {
  48.       If WinActive("Crimson Editor") and (xx < 25) ; Single Click in the Selection Area of CE
  49.       {
  50.          Send, ^c
  51.          return
  52.       }
  53.       break
  54.    }
  55.    elapsed = %A_TickCount%
  56.    elapsed -= %TimeButtonDown%
  57.    if elapsed > 200  ; Button was held down too long, so assume it's not a double-click.
  58.    {
  59.       MouseGetPos x0, y0            ; save start mouse position
  60.       Loop
  61.    {
  62.      Sleep 20                    ; yield time to others
  63.      GetKeyState keystate, LButton
  64.      IfEqual keystate, U, {
  65.        MouseGetPos x, y          ; position when button released
  66.        break
  67.      }
  68.    }
  69.    if (x-x0 > 5 or x-x0 < -5 or y-y0 > 5 or y-y0 < -5)
  70.    {                             ; mouse has moved
  71.       clip0 := ClipBoardAll      ; save old clipboard
  72.       ;ClipBoard =
  73.       Send ^c                    ; selection -> clipboard
  74.       ClipWait 1, 1              ; restore clipboard if no data
  75.       IfEqual ClipBoard,, SetEnv ClipBoard, %clip0%
  76.    }
  77.       return
  78.    }
  79. }
  80. ; Otherwise, button was released quickly enough.  Wait to see if it's a double-click:
  81. TimeButtonUp = %A_TickCount%
  82. Loop
  83. {
  84.    Sleep 10
  85.    GetKeyState, LButtonState, LButton, P
  86.    if LButtonState = D  ; Button has been pressed down again.
  87.       break
  88.    elapsed = %A_TickCount%
  89.    elapsed -= %TimeButtonUp%
  90.    if elapsed > 350  ; No click has occurred within the allowed time, so assume it's not a double-click.
  91.       return
  92. }
  93. ;Button pressed down again, it's at least a double-click
  94. TimeButtonUp2 = %A_TickCount%
  95. Loop
  96. {
  97.    Sleep 10
  98.    GetKeyState, LButtonState2, LButton, P
  99.    if LButtonState2 = U  ; Button has been released a 2nd time, let's see if it's a tripple-click.
  100.       break
  101. }
  102. ;Button released a 2nd time
  103. TimeButtonUp3 = %A_TickCount%
  104. Loop
  105. {
  106.    Sleep 10
  107.    GetKeyState, LButtonState3, LButton, P
  108.    if LButtonState3 = D  ; Button has been pressed down a 3rd time.
  109.       break
  110.    elapsed = %A_TickCount%
  111.    elapsed -= %TimeButtonUp%
  112.    if elapsed > 350  ; No click has occurred within the allowed time, so assume it's not a tripple-click.
  113.    {  ;Double-click
  114.       Send, ^c
  115.       return
  116.    }
  117. }
  118. ;Tripple-click:
  119.    Sleep, 100
  120.    Send, ^c
  121. return
  122. ~^a::Send, ^c ;Ctl+A = Select All, then Copy
  123. ~mbutton::
  124.   WinGetClass cos_class, A
  125.   ;; emacs does pasting on middleclick by itself
  126.   if (cos_class <> "Emacs")
  127.     SendInput ^v
  128.   return
复制代码


yhaisd 发表于 2017-6-11 23:46:28
本帖最后由 yhaisd 于 2017-6-12 09:46 编辑

感谢分享!
在代码的后面加 [/code]
前面加 [code]
会好看一些

另外划词翻译功能也可以通过欧路词典灵格斯词典实现


 楼主| 执黑敌夜 发表于 2017-6-11 23:52:11
yhaisd 发表于 2017-6-11 23:46
感谢分享!
在代码的后面加 [/code]
前面加 [code]

谢谢提醒
虫子 发表于 2017-6-12 01:43:06
这脚本是干嘛用的?没看懂{:5_147:}
小无奈 发表于 2017-6-12 09:05:44
我的脚本  左键选中,往下面拖动 就是复制~~~简单粗暴
传承与发展 发表于 2017-6-12 09:35:41
:L什么意思   自己做个软件?
 楼主| 执黑敌夜 发表于 2017-6-12 09:50:35
传承与发展 发表于 2017-6-12 09:35
什么意思   自己做个软件?

嗯,ahk可以做各种自动化脚本,我只是用它实现一个自己想用的小功能
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

虫部落 陕ICP备14001577号-1川公网安备 51019002003015号联系我们FAQ关于虫部落免责声明虫部落生存法则蛙先知 - AI 玩家社区 🚧

Build with for "make search easier" Copyright © 2013-2024. Powered by Discuz! GMT+8, 2024-5-9 21:47

快速回复 返回顶部 返回列表