aboutsummaryrefslogtreecommitdiff
path: root/piano.py
blob: 45a59fdcbfb0ae4a836284538c8c3f73847c3ab2 (plain)
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
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)