Created
August 1, 2016 02:28
-
-
Save atastycookie/5cb0ceca3efb65a4fe059a5eb386199c to your computer and use it in GitHub Desktop.
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
import itertools | |
class AdbText: | |
key_dict = { | |
"0": 7, "1": 8, "2": 9, "3": 10, "4": 11, "5": 12, "6": 13, "7": 14, "8": 15, "9": 16, "*": 17, | |
"#": 18, "A": 29, "B": 30, "C": 31, "D": 32, "E": 33, "F": 34, "G": 35, "H": 36, "I": 37, "J": 38, "K": 39, | |
"L": 40, "M": 41, "N": 42, "O": 43, "P": 44, "Q": 45, "R": 46, "S": 47, "T": 48, "U": 49, "V": 50, "W": 51, | |
"X": 52, "Y": 53, "Z": 54, ",": 55, ".": 56, " ": 61, " ": 62, "\n": 66, "`": 68, "-": 69, "=": 70, "[": 71, | |
"]": 72, "\\": 73, ";": 74, "'": 75, "/": 76, "@": 77, "+": 81, "(": 162, ")": 163, | |
} | |
trouble = [' ', '\n', ' ', '`'] | |
inconvenience = [';', ')', '(', "'", '\\', '&', '#', '<', '>', '|'] | |
@staticmethod | |
def get_commands(string, fast=False): | |
key_list = [] | |
count = 0 | |
for c in string: | |
count += 1 | |
if c in AdbText.trouble: | |
t = AdbText.key_dict[c] | |
key_list.append(t) | |
elif not fast and count > 7 and isinstance(key_list[-1], unicode) and len(key_list[-1]) > 7: | |
key_list.append(c) | |
else: | |
if c == '"': | |
c = '\\\\\\"' | |
elif c in AdbText.inconvenience: | |
c = '\\' + c | |
if len(key_list) > 0 and isinstance(key_list[-1], unicode) and key_list[-1][-1] != '$': | |
key_list[-1] += c | |
else: | |
key_list.append(c) | |
key_list = itertools.chain.from_iterable(("?a", 67) if item == "?" else (item,) for item in key_list) | |
commands = [] | |
for key in key_list: | |
if isinstance(key, int): | |
commands.append(['shell input keyevent %d' % key, 0.3]) | |
else: | |
key = key.replace('\n', '').replace('\r', '') | |
if key: | |
commands.append(['shell input text "' + key.replace('\n', '').replace('\r', '') + '"', 0.1]) | |
return commands |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment