-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpress.coffee
80 lines (63 loc) · 1.79 KB
/
press.coffee
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
# @ts-check
import $click from './click'
import $createList from './createList'
import $includes from './includes'
import $length from './length'
import $push from './push'
import $replace from './replace'
import $split from './split'
import $toLowerCase from './toLowerCase'
import $trim from './trim'
$formatInputPress =
###* @type import('../type/module').Press1 ###
(listInput) ->
$listKey = $createList 'string'
for $input in listInput
$ipt = $toLowerCase $input
$ipt = $replace $ipt, ' ', ''
$ipt = $replace $ipt, '-', ''
$push $listKey, ($split $ipt, '+')...
return $listKey
$validateInputPress =
###* @type import('../type/module').Press2 ###
(listInput) ->
unless $length listInput
return false
$key = listInput[0]
if $includes $key, '-button'
$key = $replace $key, 'l-button', 'left'
$key = $replace $key, 'm-button', 'middle'
$key = $replace $key, 'r-button', 'right'
$click $key
return false
return true
###* @type import('../type/module').Press ###
export default (listInput...) ->
unless $validateInputPress listInput then return
$listKey = $formatInputPress listInput
# unfold
$listResult = []
$len = $length $listKey
for $key, $i in $listKey
# last
if $i == $len - 1
$listResult[$i] = $split $key, ':'
continue
# other
if $includes $key, ':'
$listResult[$i] = $split $key, ':'
$listResult[($len - 1) * 2 - $i] = $split $key, ':'
else
$listResult[$i] = [$key, 'down']
$listResult[($len - 1) * 2 - $i] = [$key, 'up']
# alias & join
for $it, $i in $listResult
if $it[0] == 'win'
$it[0] = 'lwin'
$listResult[$i] = $trim "#{$it[0]} #{$it[1]}"
# execute
$result = ''
for $it in $listResult
$result = "#{$result}{#{$it}}"
Native 'Send, % $result'
return