-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvmkeyboard.py
More file actions
30 lines (23 loc) · 993 Bytes
/
Copy pathvmkeyboard.py
File metadata and controls
30 lines (23 loc) · 993 Bytes
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
from pynput.keyboard import Listener as keyPressListener
from json import load
from soundPlayer import playAudio
class vmKeyboard:
def __init__(this, key2soundPath) -> None:
this.key2soundPath = key2soundPath
this.defaultSoundPath = this.key2soundPath.get('default')
def handleKeyPress(this,key):
keyCapture = str(key)
this.playKey(keyCapture)
def playKey(this, key):
soundPath = this.key2soundPath.get(key,this.defaultSoundPath)
playAudio(soundPath)
if __name__ == '__main__':
key2soundPathsList = load(open('./config.json')).get('soundFilePaths')
key2soundPath = dict()
for key2soundPathdict in key2soundPathsList:
for key,value in key2soundPathdict.items():
print(key,value)
key2soundPath[key] = value
vmSoundSimulator = vmKeyboard(key2soundPath)
with keyPressListener(on_press=vmSoundSimulator.handleKeyPress,on_release=None) as listener:
listener.join()