Beeping the console

John Lenton john at grulic.org.ar
Tue Aug 31 19:21:35 EDT 2004


On Tue, Aug 31, 2004 at 03:31:31PM -0600, Jeffrey Barish wrote:
> What is the easiest way to beep the console from a Python program (i.e.,
> to do the same thing as echo -e \a)?

perhaps not 'the easiest', but:

if it's going to be running on a linux tty,

    con = file('/dev/tty', 'rw')
    fcntl.ioctl(con.fileno(),
                0x4B30, # KDMKTONE, from linux/kd.h
                1190000/2000 + (100 << 16))

will beep the speaker at 2kHz for 100 ticks.

if it's going to be running on a console that knows how to beep,

    curses.wrapper(lambda dummy: curses.beep())

(this might actually be what you're wanting, but it's only slightly
better than 'print "\a"').


me, I vote for

    os.system(conf.soundprog, conf.sounds.beep)

:)

-- 
John Lenton (john at grulic.org.ar) -- Random fortune:
Q:	Why did the programmer call his mother long distance?
A:	Because that was her name.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20040831/c9b87896/attachment.sig>


More information about the Python-list mailing list