aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2022-10-03 03:08:56 +0000
committerAnthony Wang2022-10-03 03:08:56 +0000
commit58f57624d1ec81da5586dd334b241641b21233e0 (patch)
tree5b0fdcccd919234d7c6ba786b09d56159a0af38e
parent7746413302f60823e84fa12822671e61633a54fa (diff)
Add 'piano.py'
-rw-r--r--piano.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/piano.py b/piano.py
new file mode 100644
index 0000000..45a59fd
--- /dev/null
+++ b/piano.py
@@ -0,0 +1,34 @@
+import os
+import subprocess
+from sshkeyboard import listen_keyboard
+
+p = ''
+notes = {
+ 'a': 440.00,
+ 'w': 466.16,
+ 's': 493.88,
+ 'd': 523.25,
+ 'r': 554.37,
+ 'f': 587.33,
+ 't': 622.25,
+ 'g': 659.25,
+ 'h': 698.46,
+ 'u': 739.99,
+ 'j': 783.99,
+ 'i': 830.61,
+ 'k': 880.00,
+ 'o': 932.33,
+ 'l': 987.77,
+ ';': 1046.50,
+ '[': 1108.73,
+ '\'': 1174.66
+}
+
+def press(key):
+ global p
+ p = subprocess.Popen(['beep', '-f', str(notes[key]), '-l', '100000'])
+
+def release(key):
+ os.kill(p.pid, 15)
+
+listen_keyboard(on_press=press, on_release=release)