1 |
On 2011-08-31, Space Cake <spacecakex@×××××.com> wrote: |
2 |
|
3 |
>>>>> A cheap and easy way would be to use xev to monitor a window and then |
4 |
>>>>> pipe the stderr to a a program that waits for a keypress event and |
5 |
>>>>> then plays an apropriate. |
6 |
|
7 |
Thats how I did it in Python: |
8 |
|
9 |
------------------------------------------------------------------------ |
10 |
#!/usr/bin/python |
11 |
import sys |
12 |
import subprocess |
13 |
|
14 |
soundfile = 'typewriter-key-1.wav' |
15 |
|
16 |
def main(): |
17 |
window_id = sys.argv[1] |
18 |
cmd = ['xev', '-id', window_id] |
19 |
|
20 |
p1 = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
21 |
while True: |
22 |
line = p1.stdout.readline() |
23 |
if line.find('KeyPress event') > -1: |
24 |
subprocess.Popen(['aplay', soundfile],stderr=open('/dev/null','w')) |
25 |
|
26 |
if __name__ == '__main__': |
27 |
main() |
28 |
---------------------------------------------------------------------- |
29 |
|
30 |
I don't remember where I got the typewriter-key-1.wav file from. |
31 |
|
32 |
It's amusing for about 30 seconds.... ;) |
33 |
|
34 |
-- |
35 |
Grant Edwards grant.b.edwards Yow! FUN is never having to |
36 |
at say you're SUSHI!! |
37 |
gmail.com |