左键拖选复制 + 中键粘贴 + 长按中键滚动的AHK脚本

猫在Linux里用习惯了配置后很好使的中键滚动(TP的小红点+中键来滚动神马的), 以及左键拖选/中键粘贴功能, 现在在Win下也想把他们找回来…

此脚本的效果是:

  • 左键拖选文字: 复制
  • 短按中键(<0.15s): 粘贴
  • 长按中键(>0.15s): 滚动
  • Shift+中键: 中键点击(用于浏览器新标签打开/关闭标签页等)

熟悉的朋友当然可以进一步更改这些行为以适合自己的需求^_^

*中键滚动: 虽然TrackPoint的官方驱动也提供了滚动的功能(而且算是好使), 不过他只允许中键滚动, 不能做到轻点粘贴, 此外默认情况下还不支持QQ..

**原脚本来自:

  1. http://www.autohotkey.com/forum/topic47816.html
  2. http://forum.notebookreview.com/5947142-post6.html

Felix 把这两个脚本进行了合并, 并进行了一些修改以使他们能共同工作, 以及修改了一部分的特性.

Changelog:

  • 3/25/2011: 修复切换窗口时Ctrl-C的不正常表现, 修复windows cmd界面无法复制的问题.
  • 3/24/2011: 第一个版本,基本可以做到正常工作…
$*MButton::

Hotkey, $*MButton Up, MButtonup, off
KeyWait, MButton, T0.15
If ErrorLevel = 1
{
	Hotkey, $*MButton Up, MButtonup, on
	MouseGetPos, ox, oy
 	SetTimer, WatchTheMouse, 1
	SystemCursor("Toggle")
}
Else
{
	Send {LButton}
	SendInput ^v
}
return

MButtonup:
Hotkey, $*MButton Up, MButtonup, off
SetTimer, WatchTheMouse, off
SystemCursor("Toggle")
return

WatchTheMouse:
MouseGetPos, nx, ny
dy := ny-oy
dx := nx-ox
If (dx**2 > 0 and dx**2>dy**2) ;edit 4 for sensitivity (changes sensitivity to movement)
{
	times := Abs(dy)/1 ;edit 1 for sensitivity (changes frequency of scroll signal)
	Loop, %times%
	{
		If (dx > 0)
			Click WheelRight
		Else
			Click WheelLeft
   	}
}
If (dy**2 > 0 and dy**2>dx**2) ;edit 0 for sensitivity (changes sensitivity to movement)
{
	times := Abs(dy)/1 ;edit 1 for sensitivity (changes frequency of scroll signal)
	Loop, %times% 
	{
		If (dy > 0)
			Click WheelDown
		Else
			Click WheelUp
	}   
}
MouseMove ox, oy
return

SystemCursor(OnOff=1)   ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
    static AndMask, XorMask, $, h_cursor
        ,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
        , b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13   ; blank cursors
        , h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13   ; handles of default cursors
    if (OnOff = "Init" or OnOff = "I" or $ = "")       ; init when requested or at first call
    {
        $ = h                                          ; active default cursors
        VarSetCapacity( h_cursor,4444, 1 )
        VarSetCapacity( AndMask, 32*4, 0xFF )
        VarSetCapacity( XorMask, 32*4, 0 )
        system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650
        StringSplit c, system_cursors, `,
        Loop %c0%
        {
            h_cursor   := DllCall( "LoadCursor", "uint",0, "uint",c%A_Index% )
            h%A_Index% := DllCall( "CopyImage",  "uint",h_cursor, "uint",2, "int",0, "int",0, "uint",0 )
            b%A_Index% := DllCall("CreateCursor","uint",0, "int",0, "int",0
                , "int",32, "int",32, "uint",&AndMask, "uint",&XorMask )
        }
    }
    if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
        $ = b  ; use blank cursors
    else
        $ = h  ; use the saved cursors

    Loop %c0%
    {
        h_cursor := DllCall( "CopyImage", "uint",%$%%A_Index%, "uint",2, "int",0, "int",0, "uint",0 )
        DllCall( "SetSystemCursor", "uint",h_cursor, "uint",c%A_Index% )
    }
}
return

~LButton::
cos_mousedrag_treshold := 20 ; pixels
MouseGetPos, cos_mousedrag_x, cos_mousedrag_y
win1 := WinActive("A")
KeyWait LButton
MouseGetPos, cos_mousedrag_x2, cos_mousedrag_y2
win2 := WinActive("A")
WinGetClass cos_class, A
if(((abs(cos_mousedrag_x2 - cos_mousedrag_x) > cos_mousedrag_treshold
  or abs(cos_mousedrag_y2 - cos_mousedrag_y) > cos_mousedrag_treshold)) and win1 = win2 
  and cos_class != "ConsoleWindowClass")
{
	SendInput ^c
}
return

+MButton::
Send {MButton}
return

5 thoughts on “左键拖选复制 + 中键粘贴 + 长按中键滚动的AHK脚本”

  1. 我在win10上碰到了一个很严重的问题,就是很容易出现鼠标指针从屏幕消失的情况。实际还是在的,只是看不到了。

Leave a Reply

Your email address will not be published. Required fields are marked *

QR Code Business Card