how to get a beep, OS independent ?
J. Cliff Dyer
jcd at sdf.lonestar.org
Mon Dec 8 16:05:36 EST 2008
On Sun, 2008-12-07 at 21:13 +0000, Peter Pearson wrote:
> On Sun, 07 Dec 2008 00:40:53 +0100, Stef Mientki wrote:
> >
> > I want to give a small beep,
> > for windows there's message-beep,
> > and there seems to be something like " curses" ,
> > but that package seems to be totally broken in P2.5 for windows.
> >
> > Any other suggestions ?
>
> Many people have suggested sending an ASCII 07 to your
> terminal window, but sometimes you don't have a terminal
> window.
>
> Then there's the question of using the sound card versus
> using the PC speaker. Too complicated for me.
>
> I used a kluge: a short C program that beeps the way I want,
> in this case using ioctl(fd,KDMKTONE,arg) on /dev/tty0 (this
> is Linux). The program has enough privileges to execute
> even when run by unprivileged users, and of course can be
> invoked by whatever language you're working in.
>
If you're already using /dev/tty0, why not just open a file object
on /dev/tty0, and write "\a"=="\x07" to that. No C required.
#!/usr/bin/env python
nonstdout = file("/dev/tty0")
nonstdout.write("\a")
nonstdout.flush()
(same permissions caveats apply)
On the other hand, the OP was looking for a cross-platform solution. I
don't think Windows has a /dev/tty0, but I don't work on windows, so I
can't help with cross platform issues.
Cheers,
Cliff
More information about the Python-list
mailing list