forked from dickreuter/Poker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_press_vbox.py
59 lines (49 loc) · 1.58 KB
/
key_press_vbox.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
'''
Pressing keys in virtual box from outside virtual box to solve Captchas
'''
import time
import subprocess
import pandas as pd
import os
def read_scancode_table():
df = pd.read_excel('virtualbox_scancodes.xlsx', sheetname='Sheet1')
return df
def call_virtualbox(h, vbox):
hList = h.split()
for h in hList:
param = [r"C:\Program Files\Oracle\VirtualBox\vboxmanage", "controlvm", vbox, "keyboardputscancode", h];
try:
subprocess.check_call(param)
except:
print("VMBOX keyboard entering error")
time.sleep(0.2)
def get_key_release_code(h):
dec = int(str(h), 16)
rel = dec + 128
code = hex(rel)
return (code[-2:])
def tableLookup(char, Table):
i = Table.loc[Table['Key'] == char].index.get_values()[0]
h = Table.at[i, 'Code']
s = Table.at[i, 'PressShift']
return h, s
def generate_output(input):
Table = read_scancode_table()
letters = list(input)
output = []
for letter in letters:
try:
h, s = tableLookup(letter, Table)
except:
print("Scancode Tablelookup failure")
h, s = (0, 0)
if (s == 1): output.append("36 ") # shift
r = get_key_release_code(h)
output.append(str(h) + " " + r + " ")
if (s == 1): output.append("b6 ") # shift release
return (''.join(output))
def write_characters_to_virtualbox(input, vbox):
result = (generate_output(input)) + "1C 9c" # add ENTER
call_virtualbox(result, vbox)
if __name__ == '__main__':
write_characters_to_virtualbox("Anybody around", "Windows")