-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZenHanConv.ahk
98 lines (90 loc) · 3 KB
/
ZenHanConv.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
ConvertKana(str, wideToNarrow)
{
kanaMap1 := { "ガ": "ガ", "ギ": "ギ", "グ": "グ", "ゲ": "ゲ", "ゴ": "ゴ", "ザ": "ザ", "ジ": "ジ", "ズ": "ズ", "ゼ": "ゼ", "ゾ": "ゾ", "ダ": "ダ", "ヂ": "ヂ", "ヅ": "ヅ", "デ": "デ", "ド": "ド", "バ": "バ", "ビ": "ビ", "ブ": "ブ", "ベ": "ベ", "ボ": "ボ", "ヴ": "ヴ", "ヷ": "ヷ", "ヺ": "ヺ", "ヾ": "ヾ", "パ": "パ", "ピ": "ピ", "プ": "プ", "ペ": "ペ", "ポ": "ポ" }
for k, v in kanaMap1
{
If wideToNarrow
{
StringReplace, str, str, %k%, %v%, All
}
Else
{
StringReplace, str, str, %v%, %k%, All
}
}
kanaMap2 := { "。": "。", "「": "「", "」": "」", "、": "、", "・": "・", "゠": "=", "ァ": "ァ", "ア": "ア", "ィ": "ィ", "イ": "イ", "ゥ": "ゥ", "ウ": "ウ", "ェ": "ェ", "エ": "エ", "ォ": "ォ", "オ": "オ", "カ": "カ", "キ": "キ", "ク": "ク", "ケ": "ケ", "コ": "コ", "サ": "サ", "シ": "シ", "ス": "ス", "セ": "セ", "ソ": "ソ", "タ": "タ", "チ": "チ", "ッ": "ッ", "ツ": "ツ", "テ": "テ", "ト": "ト", "ナ": "ナ", "ニ": "ニ", "ヌ": "ヌ", "ネ": "ネ", "ノ": "ノ", "ハ": "ハ", "ヒ": "ヒ", "フ": "フ", "ヘ": "ヘ", "ホ": "ホ", "マ": "マ", "ミ": "ミ", "ム": "ム", "メ": "メ", "モ": "モ", "ャ": "ャ", "ヤ": "ヤ", "ュ": "ュ", "ユ": "ユ", "ョ": "ョ", "ヨ": "ヨ", "ラ": "ラ", "リ": "リ", "ル": "ル", "レ": "レ", "ロ": "ロ", "ヮ": "ヮ", "ワ": "ワ", "ヰ": "ヰ", "ヱ": "ヱ", "ヲ": "ヲ", "ン": "ン", "ヵ": "ヵ", "ヶ": "ヶ", "ヸ": "ヸ", "ヹ": "ヹ", "・": "・", "ー": "ー", "ヽ": "ヽ", "ヿ": "ヿ" }
for k, v in kanaMap2
{
If wideToNarrow
{
StringReplace, str, str, %k%, %v%, All
}
Else
{
StringReplace, str, str, %v%, %k%, All
}
}
Return str
}
WideToNarrow(str)
{
buf =
Loop, Parse, str
{
If RegExMatch(A_LoopField, "[!-~]") > 0
{
code := Asc(A_LoopField) - 65248
buf := buf . Chr(code)
}
Else
{
buf := buf . A_LoopField
}
}
StringReplace, buf, buf, , %A_Space%, All
buf := ConvertKana(buf, true)
Return buf
}
NarrowToWide(str)
{
buf =
Loop, Parse, str
{
If RegExMatch(A_LoopField, "[!-~]") > 0
{
code := Asc(A_LoopField) + 65248
buf := buf . Chr(code)
}
Else
{
buf := buf . A_LoopField
}
}
StringReplace, buf, buf, %A_Space%, , All
buf := ConvertKana(buf, false)
Return buf
}
;--- Convert wide alphanumeric and katakana characters to narrow characters. ---;
vk1Dsc07B & n::
ClipSaved := ClipboardAll
Clipboard =
Send, ^c
ClipWait, 2, 1
Clipboard := WideToNarrow(Clipboard)
Send, ^v
Sleep 100
Clipboard := ClipSaved
ClipSaved =
Return
;--- Convert narrow alphanumeric and katakana characters to wide characters. ---;
vk1Dsc07B & w::
ClipSaved := ClipboardAll
Clipboard =
Send, ^c
ClipWait, 2, 1
Clipboard := NarrowToWide(Clipboard)
Send, ^v
Sleep 100
Clipboard := ClipSaved
ClipSaved =
Return