-
Notifications
You must be signed in to change notification settings - Fork 6
/
show_keyevent_options.py
139 lines (114 loc) · 3.79 KB
/
show_keyevent_options.py
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import re
import sys
from workflow import Workflow
from toolchain import run_script
from commands import CMD_CHECK_KEYBOARD
def wordMatch(arg, sentence):
words = arg.lower().split(" ")
sentenceComponents = sentence.lower().split(" ")
for word in words:
included = False
for sentenceComponent in sentenceComponents:
if word in sentenceComponent:
included = True
break
if not included:
return False
return True
def main(wf):
arg = wf.args[0].strip()
log.debug(arg)
addAll = False
if arg == '':
addAll = True
itemCount = 0
wf.setvar("function", "keyevent")
# Back
title = "Back"
if addAll or wordMatch(arg, title):
it = wf.add_item(title=title,
uid="KEYCODE_BACK",
arg="KEYCODE_BACK",
valid=True)
it.setvar('mod', 'none')
m = it.add_modifier('cmd', 'Long press')
m.setvar('mod', 'cmd')
m = it.add_modifier('alt', 'Double click')
m.setvar('mod', 'alt')
itemCount += 1
# Home
title = "Home"
if addAll or wordMatch(arg, title):
it = wf.add_item(title=title,
uid="KEYCODE_HOME",
arg="KEYCODE_HOME",
valid=True)
it.setvar('mod', 'none')
m = it.add_modifier('cmd', 'Long press')
m.setvar('mod', 'cmd')
itemCount += 1
# APP SWITCH
title = "App switch"
if addAll or wordMatch(arg, title + " recent"):
it = wf.add_item(title=title,
uid="KEYCODE_APP_SWITCH",
arg="KEYCODE_APP_SWITCH",
valid=True)
it.setvar('mod', 'none')
m = it.add_modifier('cmd', 'Long press')
m.setvar('mod', 'cmd')
itemCount += 1
# REBOOT SYSTEM
title = "Power"
if addAll or wordMatch(arg, title):
it = wf.add_item(title=title,
uid="KEYCODE_POWER",
arg="KEYCODE_POWER",
valid=True)
it.setvar('mod', 'none')
m = it.add_modifier('cmd', 'Long press')
m.setvar('mod', 'cmd')
itemCount += 1
# STATUS BAR
title = "Status bar"
if addAll or wordMatch(arg, title):
it = wf.add_item(title=title,
uid="STATUS_BAR",
arg="STATUS_BAR",
subtitle="Toggle status bar menu",
valid=True)
it.setvar("function", "STATUS_BAR")
itemCount += 1
# KEYBOARD
title = "Hide keyboard"
result = run_script(CMD_CHECK_KEYBOARD)
if (addAll or wordMatch(arg, title)) and "true" in result:
it = wf.add_item(title=title,
uid="KEYCODE_ESCAPE",
arg="KEYCODE_ESCAPE",
valid=True)
it.setvar('mod', 'none')
itemCount += 1
# OTHER KEYEVENTS
if re.match("keycode_\w*", arg.lower()):
it = wf.add_item(title="Other keyevents",
subtitle="input keyevent " + arg.upper(),
arg=arg.upper(),
valid=True)
it.setvar('mod', 'none')
m = it.add_modifier('cmd', 'Long press ' + arg.upper())
m.setvar('mod', 'cmd')
itemCount += 1
# INPUT TEXT
if itemCount == 0:
log.debug("arg :" + arg)
it = wf.add_item(title="Input as text",
subtitle="input text " + arg,
arg=arg,
valid=True)
it.setvar("function", "text")
wf.send_feedback()
if __name__ == '__main__':
wf = Workflow()
log = wf.logger
sys.exit(wf.run(main))