On 2011-08-31, Space Cake <spaceca...@gmail.com> wrote:

>>>>> A cheap and easy way would be to use xev to monitor a window and then
>>>>> pipe the stderr to a a program that waits for a keypress event and
>>>>> then plays an apropriate.
Thats how I did it in Python:

------------------------------------------------------------------------
#!/usr/bin/python
import sys
import subprocess

soundfile = 'typewriter-key-1.wav'

def main():
    window_id = sys.argv[1]
    cmd = ['xev', '-id', window_id]

    p1 = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    while True:
        line = p1.stdout.readline()
        if line.find('KeyPress event') > -1:
            subprocess.Popen(['aplay', soundfile],stderr=open('/dev/null','w'))

if __name__ == '__main__':
    main()
----------------------------------------------------------------------

I don't remember where I got the typewriter-key-1.wav file from.

It's amusing for about 30 seconds.... ;)
    
-- 
Grant Edwards               grant.b.edwards        Yow! FUN is never having to
                                  at               say you're SUSHI!!
                              gmail.com            


Reply via email to