Skip to content

Commit

Permalink
fix: win11兼容增强与配置修复
Browse files Browse the repository at this point in the history
  • Loading branch information
snomiao committed Dec 25, 2021
1 parent 08b2add commit df3df37
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 87 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -20,3 +20,5 @@ version-*.txt
/*.ini
*.user.*
/User
/User*
debug.log
9 changes: 5 additions & 4 deletions Core/CapslockX-Config.ahk
Expand Up @@ -20,6 +20,7 @@ if ( InStr(FileExist(便携版配置目录), "D")) {
FileCreateDir %启动配置目录%

global CapsLockX_配置目录 := 启动配置目录
; msgbox %CapsLockX_配置目录%
global CapsLockX_配置路径 := CapsLockX_配置目录 "/CapsLockX-Config.ini"

CapsLockX_ConfigInit()
Expand All @@ -40,7 +41,6 @@ CapsLockX_ConfigInit(){
global T_XKeyAsInsert := CapsLockX_Config("Core", "T_XKeyAsInsert", 0, "使用 Insert 作为引导键")
global T_XKeyAsScrollLock := CapsLockX_Config("Core", "T_XKeyAsScrollLock", 0, "使用 ScrollLock 作为引导键")
global T_XKeyAsRAlt := CapsLockX_Config("Core", "T_XKeyAsRAlt", 0, "使用 右 Alt 作为引导键")

global T_UseScrollLockLight := CapsLockX_Config("Advanced", "T_UseScrollLockLight", 0, "进阶: 是否使用 ScrollLock 灯来显示 CapsLockX 状态(不建议)")
global T_UseCapsLockLight := CapsLockX_Config("Advanced", "T_UseCapsLockLight", 0, "进阶: 是否使用 CapsLockX 灯来显示 CapsLockX 状态(强烈不建议)")
global T_SwitchSound := CapsLockX_Config("Advanced", "T_SwitchSound", 0, "进阶: 是否开启CapsLockX模式切换声音提示(默认不开)")
Expand All @@ -59,7 +59,7 @@ CapsLockX_ConfigSet(field, varName, setValue, comment := "")

CapsLockX_DontReload := 1
; 不对配置自动重新排序
if(comment) {
if (comment) {
; IniDelete, %CapsLockX_配置路径%, %field%, %varName%#注释
IniWrite, %comment%, %CapsLockX_配置路径%, %field%, %varName%#注释
}
Expand Down Expand Up @@ -95,7 +95,8 @@ CapsLockX_Config(field, varName, defaultValue, comment := "")
return content
}
清洗为_UTF16_WITH_BOM_型编码(path){
FileRead ModuleCode, %path%
FileRead content, %path%
FileDelete %path%
FileAppend %ModuleCode%, %path%, UTF-16
FileAppend %content%, %path%, UTF-16
FileRead content, %path%
}
98 changes: 62 additions & 36 deletions Modules/01-AccModel.ahk
Expand Up @@ -9,6 +9,27 @@
; ========== CapsLockX ==========
; 光标加速度微分对称模型(不要在意这中二的名字hhhh

perf_now()
{
DllCall("QueryPerformanceCounter", "Int64*", Counter)
DllCall("QueryPerformanceFrequency", "Int64*", QuadPart)
return Counter/QuadPart
}
perf_timing(showq := 1)
{
static last := perf_now()
now := perf_now()
d := now - last
static d99 := 0
static dl := 0
d99 := d99*99/100 + d*1/100
last := now
fps := 1/d99
if (showq) {
tooltip perf %fps% %d% %d99% %dl%
}
dl := d
}
class AccModel2D
{
__New(实动函数, 衰减率 := 1, 加速比率 := 1, 纵加速比率 := 0)
Expand Down Expand Up @@ -52,11 +73,11 @@ class AccModel2D
_damping(v, a, dt)
{
; 限制最大速度
if (this.最大速度){
if (this.最大速度) {
maxs := this.最大速度
v := v < -maxs ? -maxs : v
v := v > maxs ? maxs : v
if (abs(v)==maxs){
if (abs(v)==maxs) {
; tooltip 警告:达到最大速度
}
}
Expand All @@ -75,34 +96,29 @@ class AccModel2D
v:= Abs(v) < 1 ? 0 : v
Return v
}
_ticker(现刻:=0)
_ticker()
{
loop, 4 {
; 系统默认时钟频率大概64hz,有点慢
; 所以这里套一层 Looper 来提高 FPS,提升操作手感
this._tickerLooper(现刻)
Sleep, 1
}
re := this._tickerLooper()
}
_tickerLooper(现刻:=0)
_tickerLooper()
{
现刻 := 现刻 == 0 ? this._QPC() : 现刻
; 计算 dt
; 用户操作总时间计算
现刻 := this._QPC()
; dt 计算
dt := this.动刻 == 0 ? 0 : ((现刻 - this.动刻) / this._QPF())
this.动刻 := 现刻

; 计算用户操作总时间
左时 := this._dt(this.左刻, 现刻), 右时 := this._dt(this.右刻, 现刻)
上时 := this._dt(this.上刻, 现刻), 下时 := this._dt(this.下刻, 现刻)

; 同时按下相当于中键(同时也会取消自动)
if (this.左刻 && this.右刻 && Abs(右时-左时) < this.中键间隔) {
this.实动函数.Call(this._sign(右时-左时), 0, "横中键")
this.止动()
return this.实动函数.Call(this._sign(右时-左时), 0, "横中键")
return 1
}
if (this.上刻 && this.下刻 && Abs(下时-上时) < this.中键间隔) {
this.实动函数.Call(0, this._sign(下时-上时), "纵中键")
this.止动()
return this.实动函数.Call(0, this._sign(下时-上时), "纵中键")
return 1
}
; 处理移动
横加速 := this._ma(右时-左时) * this.横加速比率
Expand All @@ -112,12 +128,13 @@ class AccModel2D
this.横速 := this._damping(this.横速, 横加速, dt)
this.纵速 := this._damping(this.纵速, 纵加速, dt)

; perf_timing(1)
; 快速启动
if (!dt) {
this.启动中 := 1
this.实动函数.Call(0, 0, "启动")
this.启动中 := 0

this.横移 := this._sign(横加速)
this.纵移 := this._sign(纵加速)
}
Expand All @@ -127,48 +144,45 @@ class AccModel2D
纵输出 := this.纵移 | 0 ; 取整输出
this.横移 -= 横输出 ; 收回零头攒起来
this.纵移 -= 纵输出 ; 收回零头攒起来

; debug
msg := dt "`n" 现刻 "`n" this.动刻 "`n" 横加速 "`n" this.横速 "`n" this.横移 "`n" this.横输出
; msg := dt "`n" 现刻 "`n" this.动刻 "`n" 横加速 "`n" this.横速 "`n" this.横移 "`n" this.横输出
; tooltip %msg%

if (横输出 || 纵输出) {
; tooltip %dt% %横输出% %纵输出% %横加速% %纵加速%
this.实动函数.Call(横输出, 纵输出, "移动")
}
; 要求的键弹起,结束定时器
if (this.左等键 && !GetKeyState(this.左等键, "P")){
this.左等键 := ""
this.左放()
if (this.左等键 && !GetKeyState(this.左等键, "P")) {
this.左等键 := "", this.左放()
}
if (this.右等键 && !GetKeyState(this.右等键, "P")){
this.右等键 := ""
this.右放()
if (this.右等键 && !GetKeyState(this.右等键, "P")) {
this.右等键 := "", this.右放()
}
if (this.上等键 && !GetKeyState(this.上等键, "P")){
this.上等键 := ""
this.上放()
if (this.上等键 && !GetKeyState(this.上等键, "P")) {
this.上等键 := "", this.上放()
}
if (this.下等键 && !GetKeyState(this.下等键, "P")){
this.下等键 := ""
this.下放()
if (this.下等键 && !GetKeyState(this.下等键, "P")) {
this.下等键 := "", this.下放()
}
; 速度归 0,结束定时器
if ( !this.横速 && !this.纵速 && !(横输出 || 纵输出)) {
this.止动()
Return
return 0
}
return 1
}
始动() {
this.动刻 := 0
this.ticker()
this._ticker()
时钟 := this.时钟
SetTimer % 时钟, % this.间隔
SetTimer % 时钟, % 0
}
止动(){
时钟 := this.时钟
SetTimer % 时钟, Off
if (this.动刻 != 0){
if (this.动刻 != 0) {
this.动刻 := 0
this.实动函数.Call(0, 0, "止动")
}
Expand All @@ -181,6 +195,9 @@ class AccModel2D
this.上等键 := "", this.下等键 := ""
}
左按(左等键:=""){
if (this.左等键) {
return
}
this.左等键 := 左等键
this.左刻 := this.左刻 ? this.左刻 : this._QPC()
this.始动()
Expand All @@ -189,6 +206,9 @@ class AccModel2D
this.左刻 := 0
}
右按(右等键:=""){
if (this.右等键) {
return
}
this.右等键 := 右等键
this.右刻 := this.右刻 ? this.右刻 : this._QPC()
this.始动()
Expand All @@ -197,6 +217,9 @@ class AccModel2D
this.右刻 := 0
}
上按(上等键:=""){
if (this.上等键) {
return
}
this.上等键 := 上等键
this.上刻 := this.上刻 ? this.上刻 : this._QPC()
this.始动()
Expand All @@ -205,6 +228,9 @@ class AccModel2D
this.上刻 := 0
}
下按(下等键:=""){
if (this.下等键) {
return
}
this.下等键 := 下等键
this.下刻 := this.下刻 ? this.下刻 : this._QPC()
this.始动()
Expand Down
91 changes: 66 additions & 25 deletions Modules/01.1-插件-鼠标模拟.ahk
Expand Up @@ -91,6 +91,38 @@ SendInput_MouseMsg32(dwFlag, mouseData := 0)
NumPut(dwFlag, sendData, 16, "UInt")
DllCall("SendInput", "UInt", 1, "Str", sendData, "UInt", 28)
}

SendInput_ScrollMouse(dx, dy)
{
; get cursor pos
VarSetCapacity(POINT, 8, 0)
DllCall("GetCursorPos", "Ptr", &POINT)
x := NumGet(POINT, 0, "Int")
y := NumGet(POINT, 4, "Int")
; scroll by system input message
MOUSEEVENTF_WHEEL := 0x0800
MOUSEEVENTF_HWHEEL := 0x1000
if (dx) {
size := A_PtrSize+4*4+A_PtrSize
VarSetCapacity(mi, size, 0)
NumPut(x, mi, A_PtrSize, "Int") ; LONG dx
NumPut(y, mi, A_PtrSize+4, "Int") ; LONG dy
NumPut(dx, mi, A_PtrSize+4+4, "Int") ; DWORD mouseData
NumPut(MOUSEEVENTF_HWHEEL, mi, A_PtrSize+4+4+4, "UInt") ; DWORD dwFlags
DllCall("SendInput", "UInt", 1, "Ptr", &mi, "Int", size )
}
if (dy) {
size := A_PtrSize+4*4+A_PtrSize*2
VarSetCapacity(mi, size, 0)
NumPut(x, mi, A_PtrSize, "Int") ; LONG dx
NumPut(y, mi, A_PtrSize+4, "Int") ; LONG dy
NumPut(dy, mi, A_PtrSize+4+4, "Int") ; DWORD mouseData
NumPut(MOUSEEVENTF_WHEEL, mi, A_PtrSize+4+4+4, "UInt") ; DWORD dwFlags
DllCall("SendInput", "UInt", 1, "Ptr", &mi, "Int", size )
; perf_timing()
}
}

SendInput_MouseMove(x, y)
{
; (20211105)终于支持64位了
Expand All @@ -104,6 +136,11 @@ SendInput_MouseMove(x, y)
NumPut(0x0001, mi, A_PtrSize+4+4+4, "UInt") ; DWORD dwFlags MOUSEEVENTF_MOVE
DllCall("SendInput", "UInt", 1, "Ptr", &mi, "Int", size )
}
鼠标模拟2(dx, dy){
SendInput_MouseMove(dx, dy)

}

; void 鼠标模拟
鼠标模拟(dx, dy, 状态){
if (!CapsLockXMode) {
Expand Down Expand Up @@ -143,10 +180,10 @@ SendInput_MouseMove(x, y)
; 鼠标模拟.纵速 *= dy && ya == yb ? 0 : 1


; 在各种按钮上减速,进出按钮时减速50%
; 在各种按钮上减速,进出按钮时减速80%
if (TMouse_StickyCursor && CursorShapeChangedQ()) {
鼠标模拟.横速 *= 0.5
鼠标模拟.纵速 *= 0.5
鼠标模拟.横速 *= 0.2
鼠标模拟.纵速 *= 0.2
}
}

Expand Down Expand Up @@ -191,18 +228,19 @@ SendInput_MouseMove(x, y)
}
WM_MOUSEWHEEL := 0x020A
WM_MOUSEWHEELH := 0x020E
_:= dy && 滚轮消息发送(WM_MOUSEWHEEL, -dy)
_:= dx && 滚轮消息发送(WM_MOUSEWHEELH, dx)
if (!TMouse_SendIputAPI) {
SendInput_ScrollMouse(dx, -dy)
} else {
_:= dy && 滚轮消息发送(WM_MOUSEWHEEL, -dy)
_:= dx && 滚轮消息发送(WM_MOUSEWHEELH, dx)
}
}

滚轮消息发送(msg, zDelta){
; 目前还不支持UWP
CoordMode, Mouse, Screen
MouseGetPos, x, y, wid, fcontrol

wParam := zDelta << 16 ;zDelta
lParam := x | (y << 16) ; pos2long

MouseGetPos, , , , ControlClass2, 2
MouseGetPos, , , , , ControlClass3, 3
if (A_Is64bitOS) {
Expand Down Expand Up @@ -246,7 +284,6 @@ CapsLockX_鼠标右键按下(wait){
CapsLockX_鼠标右键弹起(){
SendEvent {Blind}{RButton Up}
}

鼠标模拟_ToolTip(tips){
ToolTip %tips%
SetTimer 鼠标模拟_ToolTipRemove, -3000
Expand All @@ -258,21 +295,25 @@ CapsLockX_鼠标右键弹起(){
#if CapsLockXMode

; 鼠标按键处理
$*e::CapsLockX_鼠标左键按下("e")
$*q:: CapsLockX_鼠标右键按下("q")
$*e Up::CapsLockX_鼠标左键弹起()
$*q Up:: CapsLockX_鼠标右键弹起()
*e::CapsLockX_鼠标左键按下("e")
*q:: CapsLockX_鼠标右键按下("q")
*e Up::CapsLockX_鼠标左键弹起()
*q Up:: CapsLockX_鼠标右键弹起()
; 鼠标运动处理
$*a:: 鼠标模拟.左按("a")
$*d:: 鼠标模拟.右按("d")
$*w:: 鼠标模拟.上按("w")
$*s:: 鼠标模拟.下按("s")
*a:: 鼠标模拟.左按("a")
*d:: 鼠标模拟.右按("d")
*w:: 鼠标模拟.上按("w")
*s:: 鼠标模拟.下按("s")
; 滚轮运动处理
$*+^!r:: 滚轮自动控制.左按("r")
$*+^!f:: 滚轮自动控制.右按("f")
$*^!r:: 滚轮自动控制.上按("r")
$*^!f:: 滚轮自动控制.下按("f")
$*+r:: 滚轮模拟.左按("r")
$*+f:: 滚轮模拟.右按("f")
$*r:: 滚轮模拟.上按("r")
$*f:: 滚轮模拟.下按("f")
; *+^!r:: 滚轮自动控制.左按("r")
; *+^!f:: 滚轮自动控制.右按("f")
*^![:: 滚轮自动控制.左按("[")
*^!]:: 滚轮自动控制.右按("]")
; *^!r:: 滚轮自动控制.上按("r")
; *^!f:: 滚轮自动控制.下按("f")
; *+r:: 滚轮模拟.左按("r")
; *+f:: 滚轮模拟.右按("f")
*r:: 滚轮模拟.上按("r")
*f:: 滚轮模拟.下按("f")
*[:: 滚轮模拟.左按("[")
*]:: 滚轮模拟.右按("]")
3 changes: 3 additions & 0 deletions Modules/01.1-插件-鼠标模拟.md
Expand Up @@ -26,3 +26,6 @@
| 全局 | `CapsLockX + rf ` | rf 同时按相当于鼠标中键 |
| 全局 | `CapsLockX + e ` | 鼠标左键 |
| 全局 | `CapsLockX + q ` | 鼠标右键 |

## 操作细节
快速连按AD步进

0 comments on commit df3df37

Please sign in to comment.