AHK "driver" for Thinkpad Keyboards - 小红点按下中键,用指点杆上下左右滚动页面

许多实用脚本和封装函数, 可以让您编写脚本更加便捷高效

Moderators: tmplinshi, arcticir

Post Reply
llinfeng
Posts: 76
Joined: 08 Dec 2016, 21:54
GitHub: llinfeng

AHK "driver" for Thinkpad Keyboards - 小红点按下中键,用指点杆上下左右滚动页面

Post by llinfeng » 05 Apr 2020, 19:12

使用:最保险的方法是删除ThinkPad键盘自己会装上去的驱动,名字大概叫“Thinkpad compact keyboard with bluetooth”,或是有“ThinkPad”字号的驱动。整段下面的代码,可以直接添加到日常运行在托盘的ahk程序中,不需要单独创建新文件并运行(单独创建新文件的话,该需要加#InstallKeybdHook
#UseHook,On
#SingleInstance ; Allow only one instance of this script to be running.
#Persistent ; To stop the script from exiting.
)一类的语句在“autoexecute section”(也就是整个ahk文件第一个return之前的地方)里面。

如有需要,会在GitHub的这个Gist上更新。

Code: Select all

; Midbutton down for scrolling {{{
; Feature: with acceleration as intended.
; Source: http://forum.notebookreview.com/threads/ultranav-middle-click-button-scroll.423415/
; Linking source: ettps://superuser.com/questions/91074/thinkpad-trackpoint-scrolling-and-middle-click-possible
; Working version {{{
$*MButton::
Hotkey, $*MButton Up, MButtonup, off
KeyWait, MButton, T0.2
If ErrorLevel = 1
{
	Hotkey, $*MButton Up, MButtonup, on
	MouseGetPos, ox, oy
 	SetTimer, WatchTheMouse, 5
	SystemCursor("Toggle")
}
Else
	Send {MButton}
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% )
    }
}
; }}}
; }}}

llinfeng
Posts: 76
Joined: 08 Dec 2016, 21:54
GitHub: llinfeng

Re: AHK "driver" for Thinkpad Keyboards - 小红点按下中键,用指点杆上下左右滚动页面

Post by llinfeng » 26 Apr 2020, 13:40

llinfeng wrote:
05 Apr 2020, 19:12
使用:最保险的方法是删除ThinkPad键盘自己会装上去的驱动,名字大概叫“Thinkpad compact keyboard with bluetooth”,
保留原有的 ThinkPad Keyboard 驱动该也能正常工作,但要记得取消对“ThinkPad Preferred Scrolling”的勾选,如图:Image

另外,这个脚本起两个作用:1. 保留原先按住中键上下滚动的功能;2. 保留单击中键的功能。
Post Reply

Return to “脚本函数”