[C] 纯文本查看 复制代码
#Requires AutoHotkey v2.0
#SingleInstance Force
; ========== 配置文件 ==========
ConfigFile := A_ScriptDir . "\PotPlayerSpeed.ini"
; ========== 默认配置 ==========
DefaultKeys := ["A", "S", "D", "F", "G", "H", "J", "K", "L", ";"]
DefaultSpeeds := [1.0, 1.2, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
Global Keys := DefaultKeys.Clone()
Global Speeds := DefaultSpeeds.Clone()
; ========== 速度追踪(每次打开脚本都是1.0)==========
Global CurrentSpeed := 1.0
Global AutoSaveTimer := 0
; ========== 辅助函数 ==========
RoundOne(num)
{
return Round(num, 1)
}
; ========== 加载配置(只加载按键和速度设置,不加载当前速度)==========
LoadConfig()
; ========== GUI界面 ==========
MyGui := Gui(, "PotPlayer 速度控制器")
MyGui.SetFont("s10", "Segoe UI")
MyGui.Add("Text", "xm y10 w50", "按键")
MyGui.Add("Text", "x+10 w70", "倍数")
MyGui.Add("Text", "x+10 w40", "")
KeyEdits := []
SpeedEdits := []
Loop 10
{
yPos := 40 + (A_Index - 1) * 32
currentKey := Keys[A_Index]
currentSpeed := RoundOne(Speeds[A_Index])
keyCtrl := MyGui.Add("Edit", "xm y" yPos " w50 center", currentKey)
keyCtrl.OnEvent("Change", KeyChanged)
KeyEdits.Push(keyCtrl)
speedCtrl := MyGui.Add("Edit", "x+10 y" yPos " w70", currentSpeed)
speedCtrl.OnEvent("Change", SpeedChanged)
MyGui.Add("Text", "x+10 y" yPos " w40", "倍速")
SpeedEdits.Push(speedCtrl)
}
MyGui.Add("Text", "xm y362 w260 0x7")
MyGui.Add("Text", "xm y382 w40", "当前:")
CurrentDisplay := MyGui.Add("Text", "x+10 y380 w60 center 0x200", "1.0x")
CurrentDisplay.SetFont("s12 bold")
SaveBtn := MyGui.Add("Button", "x+20 y377 w70", "保存")
SaveBtn.OnEvent("Click", (*) => SaveConfig())
ResetBtn := MyGui.Add("Button", "x+10 y377 w70", "重置")
ResetBtn.OnEvent("Click", (*) => ResetToDefault())
MyGui.Show("w280 h432")
; ========== 按键修改 ==========
KeyChanged(ctrl, *)
{
global Keys, KeyEdits, AutoSaveTimer
index := 0
Loop 10
{
if (KeyEdits[A_Index] == ctrl)
{
index := A_Index
break
}
}
if (index == 0)
return
newKey := ctrl.Value
if (newKey == "")
return
newKey := SubStr(StrUpper(newKey), 1, 1)
; 检查冲突
Loop 10
{
if (A_Index != index and Keys[A_Index] == newKey)
{
ctrl.Value := Keys[index]
return
}
}
Keys[index] := newKey
ctrl.Value := newKey
if (AutoSaveTimer)
SetTimer(AutoSaveTimer, 0)
AutoSaveTimer := SetTimer(SaveConfig, -2000)
}
; ========== 速度修改 ==========
SpeedChanged(ctrl, *)
{
global Speeds, SpeedEdits, AutoSaveTimer
index := 0
Loop 10
{
if (SpeedEdits[A_Index] == ctrl)
{
index := A_Index
break
}
}
if (index == 0)
return
editValue := ctrl.Value
if (editValue == "")
return
newVal := RoundOne(Float(editValue))
if (newVal < 0.2)
newVal := 0.2
if (newVal > 16.0)
newVal := 16.0
Speeds[index] := newVal
ctrl.Value := newVal
if (AutoSaveTimer)
SetTimer(AutoSaveTimer, 0)
AutoSaveTimer := SetTimer(SaveConfig, -2000)
}
; ========== 保存 ==========
SaveConfig()
{
global Keys, Speeds, AutoSaveTimer
if (AutoSaveTimer)
{
SetTimer(AutoSaveTimer, 0)
AutoSaveTimer := 0
}
IniWrite(Keys[1], ConfigFile, "Keys", "Key1")
IniWrite(Keys[2], ConfigFile, "Keys", "Key2")
IniWrite(Keys[3], ConfigFile, "Keys", "Key3")
IniWrite(Keys[4], ConfigFile, "Keys", "Key4")
IniWrite(Keys[5], ConfigFile, "Keys", "Key5")
IniWrite(Keys[6], ConfigFile, "Keys", "Key6")
IniWrite(Keys[7], ConfigFile, "Keys", "Key7")
IniWrite(Keys[8], ConfigFile, "Keys", "Key8")
IniWrite(Keys[9], ConfigFile, "Keys", "Key9")
IniWrite(Keys[10], ConfigFile, "Keys", "Key10")
IniWrite(RoundOne(Speeds[1]), ConfigFile, "Speeds", "Speed1")
IniWrite(RoundOne(Speeds[2]), ConfigFile, "Speeds", "Speed2")
IniWrite(RoundOne(Speeds[3]), ConfigFile, "Speeds", "Speed3")
IniWrite(RoundOne(Speeds[4]), ConfigFile, "Speeds", "Speed4")
IniWrite(RoundOne(Speeds[5]), ConfigFile, "Speeds", "Speed5")
IniWrite(RoundOne(Speeds[6]), ConfigFile, "Speeds", "Speed6")
IniWrite(RoundOne(Speeds[7]), ConfigFile, "Speeds", "Speed7")
IniWrite(RoundOne(Speeds[8]), ConfigFile, "Speeds", "Speed8")
IniWrite(RoundOne(Speeds[9]), ConfigFile, "Speeds", "Speed9")
IniWrite(RoundOne(Speeds[10]), ConfigFile, "Speeds", "Speed10")
}
; ========== 加载(只加载按键和速度数值,CurrentSpeed始终为1)==========
LoadConfig()
{
global Keys, Speeds, DefaultKeys, DefaultSpeeds
Loop 10
{
savedKey := IniRead(ConfigFile, "Keys", "Key" . A_Index, DefaultKeys[A_Index])
Keys[A_Index] := (savedKey != "") ? SubStr(StrUpper(savedKey), 1, 1) : DefaultKeys[A_Index]
savedSpeed := IniRead(ConfigFile, "Speeds", "Speed" . A_Index, DefaultSpeeds[A_Index])
Speeds[A_Index] := IsNumber(savedSpeed) ? RoundOne(Float(savedSpeed)) : DefaultSpeeds[A_Index]
}
; CurrentSpeed 不保存,每次打开都是 1.0
}
; ========== 重置 ==========
ResetToDefault()
{
global Keys, Speeds, DefaultKeys, DefaultSpeeds, KeyEdits, SpeedEdits
Loop 10
{
Keys[A_Index] := DefaultKeys[A_Index]
Speeds[A_Index] := DefaultSpeeds[A_Index]
KeyEdits[A_Index].Value := Keys[A_Index]
SpeedEdits[A_Index].Value := Speeds[A_Index]
}
SaveConfig()
}
; ========== 速度函数 ==========
SetSpeed(presetIndex)
{
global Speeds, CurrentSpeed, CurrentDisplay
target := Speeds[presetIndex]
if (target == CurrentSpeed)
return
diff := target - CurrentSpeed
steps := Round(diff / 0.1)
if (steps > 0)
{
Loop steps
{
Send("c")
}
}
else if (steps < 0)
{
Loop -steps
{
Send("x")
}
}
CurrentSpeed := target
CurrentDisplay.Value := RoundOne(target) . "x"
}
; ========== 热键 ==========
#HotIf WinActive("ahk_class PotPlayer64 ahk_exe PotPlayerMini64.exe")
$A::SetSpeed(1)
$S::SetSpeed(2)
$D::SetSpeed(3)
$F::SetSpeed(4)
$G::SetSpeed(5)
$H::SetSpeed(6)
$J::SetSpeed(7)
$K::SetSpeed(8)
$L::SetSpeed(9)
$;::SetSpeed(10)
#HotIf