-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (26 loc) · 999 Bytes
/
main.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
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
import os
import mido
import time
from piano import keys,notes
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir={}\driver_data".format(os.getcwd()))
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)
driver.get("https://www.onlinepianist.com/virtual-piano")
time.sleep(5)
el = driver.find_element_by_id("keyboardButton")
ActionChains(driver).move_to_element(el).click().perform()
el = driver.find_element_by_tag_name("body")
pattern = mido.MidiFile(r"E:\nameOfLife.mid")
for msg in pattern.play():
try:
if len(notes[msg.note])==3:
el.send_keys(Keys.SHIFT+keys[notes[msg.note]])
else:
el.send_keys(keys[notes[msg.note]])
except:
continue
driver.close()