-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
; 雪星并击 | snochorded | ||
; Copyright 2020 [email protected] | ||
; LICENSE - GPLv3 | ||
; (20200722) 创建 | ||
; Save this file as utf8 with bom | ||
; ========== CapsLockX ========== | ||
; 名称:雪星并击 | snochorded | ||
; 描述:启用雪星并击,创建于(20200722) 文档请见主页 [雪星并击 snochorded sno-chord-typing | snochorded]( https://snomiao.github.io/snochorded/ ) | ||
; 作者:snomiao | ||
; 联系:[email protected] | ||
; 支持:[雪星并击 snochorded sno-chord-typing | snochorded]( https://snomiao.github.io/snochorded/ ) | ||
; 版权:Copyright 2020-2022 [email protected] | ||
; 版本:v0.0.1 | ||
; ========== CapsLockX ========== | ||
|
||
; update: https://github.com/snomiao/snochorded/raw/master/%E9%9B%AA%E6%98%9F%E5%B9%B6%E5%87%BB.ahk | ||
|
||
FileEncoding, UTF-8 | ||
|
||
; 開關 默认关 | ||
global SnoChordTypingEnable := CapsLockX_Config("Plugins", "EnableSnoChordTyping", 0, "启用雪星并击(实验中),") | ||
if (!SnoChordTypingEnable) | ||
if (!T_SnoChordTypingEnable) | ||
Return | ||
|
||
雪星并击_初始化() | ||
|
@@ -24,12 +29,12 @@ Return | |
global SnoChordTypingAllowRewrite := 0 | ||
global SnoChordTypingAppendSpace := 0 | ||
global SnoChordTypingStageList := [] | ||
|
||
; 变量 | ||
global SnoChordTypingPressedKeySet := {} | ||
global SnoChordTypingTypedKeys := "" | ||
global SnoChordTypingLastKeyDownTick := 0 | ||
|
||
; 读入配置 | ||
ConfigPath := CapsLockX_配置目录 "/雪星并击配置.ini" | ||
IniRead, SnoChordTypingChordIntervalThreshold, %ConfigPath%, Common, SnoChordTypingChordIntervalThreshold, %SnoChordTypingChordIntervalThreshold% | ||
|
@@ -41,7 +46,7 @@ Return | |
IniRead, SnoChordTypingAppendSpace, %ConfigPath%, Common, SnoChordTypingAppendSpace, %SnoChordTypingAppendSpace% | ||
IniWrite, %SnoChordTypingAppendSpace%, %ConfigPath%, Common, SnoChordTypingAppendSpace | ||
; MsgBox, , , SnoChordTypingAllowRewriteString: %SnoChordTypingAllowRewriteString% | ||
|
||
; 默认键位数据 | ||
RuleStage1 :=" | ||
( | ||
|
@@ -57,9 +62,9 @@ Return | |
=| wq => p | eq => o | ew => i | rw => u | re => y | | ||
=| as => ; | ad => l | sd => k | sf => j | df => h | | ||
=| sa => ; | da => l | ds => k | fs => j | fd => h | | ||
=| zx => / | zc => . | xc => , | xv => m | cv => n | | ||
=| xz => / | cz => . | cx => , | vx => m | vc => n | | ||
|
||
=| zx => / | zc => . | xc =>, | xv => m | cv => n | | ||
=| xz => / | cz => . | cx =>, | vx => m | vc => n | | ||
)" | ||
RuleStage2 := " | ||
( | ||
|
@@ -68,16 +73,16 @@ Return | |
=| _6 => 6 | _7 => 7 | _8 => 8 | _9 => 9 | _0 => 0 | | ||
=| _y => y | _u => u | _i => i | _o => o | _p => p | | ||
=| _h => h | _j => j | _k => k | _l => l | _; => ; | | ||
=| _n => n | _m => m | _, => , | _. => . | _/ => / | | ||
=| _n => n | _m => m | _, =>, | _. => . | _/ => / | | ||
=| 78 => 5 | 79 => 4 | 89 => 3 | 08 => 2 | 09 => 1 | | ||
=| 87 => 5 | 97 => 4 | 98 => 3 | 80 => 2 | 90 => 1 | | ||
=| ui => t | uo => r | io => e | pi => w | po => q | | ||
=| iu => t | ou => r | oi => e | ip => w | op => q | | ||
=| jk => g | jl => f | kl => d | ;k => s | ;l => a | | ||
=| kj => g | lj => f | lk => d | k; => s | l; => a | | ||
=| m, => b | m. => v | ,. => c | /, => x | /. => z | | ||
=| ,m => b | .m => v | ., => c | ,/ => x | ./ => z | | ||
|
||
=| m, => b | m. => v |, . => c | /, => x | /. => z | | ||
=|, m => b | .m => v | ., => c |, / => x | ./ => z | | ||
)" | ||
RuleStage3 := " | ||
( | ||
|
@@ -86,48 +91,47 @@ Return | |
=| _- => - | _= => = | _[ => [ | _] => ] | _\ => \ | | ||
=| _' => ' | __ => _ | | ||
)" | ||
; 编译键位数据 | ||
StageIndex := 1 | ||
while(1){ | ||
while (1) { | ||
IniRead, RuleStage, %ConfigPath%, RuleStage%StageIndex% | ||
; MsgBox ,,, % "asdf" RuleStage "zxcv" StageIndex "asdf" !RuleStage | ||
If (!RuleStage) | ||
; MsgBox, , , % "asdf" RuleStage "zxcv" StageIndex "asdf" !RuleStage | ||
if (!RuleStage) | ||
Break | ||
RuleStage%StageIndex% := RuleStage | ||
; MsgBox, , , RuleStage: %RuleStage% | ||
|
||
objRule := {} | ||
FoundPos := 0 | ||
while(FoundPos := RegExMatch(RuleStage, "O)\s_*?(\S+)\s*?=>\s*?(\S+)\s", SubPat, FoundPos+1)) | ||
{ | ||
while (FoundPos := RegExMatch(RuleStage, "O)\s_*?(\S+)\s*?=>\s*?(\S+)\s", SubPat, FoundPos+1)) { | ||
MapFrom := "" SubPat.Value(1) | ||
MapTo := SubPat.Value(2) "" | ||
|
||
; MsgBox ,,, % SubPat.Value(1) "=" SubPat.Value(2) | ||
|
||
; MsgBox, , , % SubPat.Value(1) "=" SubPat.Value(2) | ||
MapFrom := StrReplace(MapFrom, "_", " ") | ||
MapTo := StrReplace(MapTo, "_", " ") | ||
|
||
objRule[MapFrom] := MapTo | ||
} | ||
|
||
objKeys := {} | ||
lsKey := [] | ||
RightHandKeysSet := [] | ||
For Keys, _ in objRule{ | ||
; MsgBox ,,, % "Keys" Keys | ||
for Keys, _ in objRule { | ||
; MsgBox, , , % "Keys" Keys | ||
KeysList := StrSplit(Keys) | ||
Loop % KeysList.MaxIndex() | ||
{ | ||
Key := KeysList[A_Index] | ||
Key := StrReplace(Key, "_", " ") | ||
; MsgBox ,,, % Key | ||
; MsgBox, , , % Key | ||
objKeys[Key] := 1 | ||
} | ||
} | ||
For Key, _ in objKeys{ | ||
; MsgBox ,,, % Key | ||
for Key, _ in objKeys { | ||
; MsgBox, , , % Key | ||
lsKey.Push(Key) | ||
} | ||
Stage := {"objKeys": objKeys, "lsKey": lsKey, "objRule": objRule, "Pressed": "", "Typed": ""} | ||
|
@@ -138,30 +142,31 @@ Return | |
IniWrite, %RuleStage1%, %ConfigPath%, RuleStage1 | ||
IniWrite, %RuleStage2%, %ConfigPath%, RuleStage2 | ||
IniWrite, %RuleStage3%, %ConfigPath%, RuleStage3 | ||
|
||
; 挂载并击热键 | ||
Hotkey, if, !CapsLockXMode | ||
For _, Stage in SnoChordTypingStageList{ | ||
For _, KeyName in Stage["lsKey"]{ | ||
for _, Stage in SnoChordTypingStageList { | ||
for _, KeyName in Stage["lsKey"]{ | ||
KeyName := StrReplace(KeyName, " ", "Space") | ||
; 只有字母直接按下会不导致输入法上屏 | ||
if (SnoChordTypingAllowRewrite && InStr(SnoChordTypingAllowRewriteString, KeyName)){ | ||
if (SnoChordTypingAllowRewrite && InStr(SnoChordTypingAllowRewriteString, KeyName)) { | ||
Hotkey, ~$%KeyName%, SnoChordKeyDown | ||
Hotkey, ~$+%KeyName%, SnoChordKeyDown | ||
}else{ | ||
} else { | ||
Hotkey, $%KeyName%, SnoChordKeyDown | ||
Hotkey, $+%KeyName%, SnoChordKeyDown | ||
} | ||
Hotkey, ~$*%KeyName% Up, SnoChordKeyUp | ||
} | ||
} | ||
Hotkey, if, | ||
|
||
Hotkey, if, | ||
} | ||
|
||
snochorded_output_recored_keys(){ | ||
snochorded_output_recored_keys() | ||
{ | ||
OutputKey := "" | ||
For _, Stage in SnoChordTypingStageList { | ||
for _, Stage in SnoChordTypingStageList { | ||
StagePressed := Stage["Pressed"] | ||
Replaced := Stage["objRule"][StagePressed ""] | ||
OutputKey .= Replaced ? Replaced : StagePressed | ||
|
@@ -173,46 +178,49 @@ snochorded_output_recored_keys(){ | |
; Clean | ||
SnoChordTypingLastKeyDownTick := 0 | ||
SnoChordTypingTypedKeys := "" | ||
if (OutputChanged && OutputLength){ | ||
if (OutputChanged && OutputLength) { | ||
; OutputKey .= " " | ||
OutputKey := "{blind}" . OutputKey | ||
Loop, % lenTyped | ||
loop, % lenTyped { | ||
OutputKey := "{BackSpace}" . OutputKey | ||
} | ||
; send event is most stable | ||
SendEvent % OutputKey | ||
} | ||
if (SnoChordTypingAppendSpace){ | ||
if (SnoChordTypingAppendSpace) { | ||
SendEvent % " " | ||
} | ||
} | ||
|
||
SnoChordKeyDown(){ | ||
SnoChordKeyDown() | ||
{ | ||
NowTick := A_TickCount | ||
ThisKey := A_ThisHotkey | ||
ThisKey := StrReplace(ThisKey, "~") | ||
ThisKey := StrReplace(ThisKey, "$") | ||
ThisKey := StrReplace(ThisKey, "+") | ||
ThisKey := StrReplace(ThisKey, "Space", " ") | ||
|
||
if ( SnoChordTypingLastKeyDownTick == 0 | ||
|| NowTick - SnoChordTypingLastKeyDownTick <= SnoChordTypingChordIntervalThreshold){ | ||
if (SubStr(A_ThisHotkey, 1, 1)=="~"){ | ||
|| NowTick - SnoChordTypingLastKeyDownTick <= SnoChordTypingChordIntervalThreshold){ | ||
if (SubStr(A_ThisHotkey, 1, 1)=="~") { | ||
SnoChordTypingTypedKeys .= ThisKey | ||
} | ||
}else{ | ||
} else { | ||
snochorded_output_recored_keys() | ||
} | ||
|
||
For StageIndex, Stage in SnoChordTypingStageList{ | ||
if (Stage["objKeys"].HasKey(ThisKey)){ | ||
for StageIndex, Stage in SnoChordTypingStageList { | ||
if (Stage["objKeys"].HasKey(ThisKey)) { | ||
Stage["Pressed"] .= ThisKey | ||
Break | ||
} | ||
} | ||
SnoChordTypingLastKeyDownTick := NowTick | ||
} | ||
|
||
SnoChordKeyUp(){ | ||
SnoChordKeyUp() | ||
{ | ||
snochorded_output_recored_keys() | ||
; PressedKeys is only for debug | ||
; if (PressedKeys) | ||
|