On Wed, Dec 07, 2005, Omer Zak wrote about "Re: Broadband (fast) Internet 
related accessibility issues":
> > If you're interested, I can show you a tiny piece of code I wrote that
> > captures these beeps, and does something else (in my case, I wanted to
> > flash the screen, and play a fancy beep music).
> 
> Yes, please show me.

Here's a first - source code on this open-source list :-) But it's so short,
I hope nobody minds. I took out the ESD sound playing code (which is obviously
of no interest to you), and left only the minimal capturing code. You can
replace the silly "printf" with anything you want.

You might also want to check out xsoundentry (if available on your system)
and fancybell (http://www.hypercore.co.jp/opensource/fancybell/) on which
my code was orignally based.

Compile the following code with "cc file.c -L/usr/X11R6/lib -lX11" (or
something similar).

/* capture bell events (using Xkb extensions) and do something.
*/

#include <stdio.h>
#include <X11/XKBlib.h>

int main(int argc, char **argv){
        Display *dpy;
        unsigned int bit1 = XkbAudibleBellMask, bit2 = XkbAudibleBellMask;
        XEvent event;
        int major = XkbMajorVersion, minor = XkbMinorVersion, Xkb_event_base;

        if(!(dpy=XOpenDisplay(NULL))){
                fprintf(stderr,"%s: Unable to open display\n",argv[0]);
                exit(1);
        }
        
        /* initialize Xkb */
        if (!XkbLibraryVersion(&major, &minor) ||
            !XkbQueryExtension(dpy, NULL, &Xkb_event_base, NULL, &major, 
&minor)){
                fprintf(stderr,"%s: No Xkb extension on display?\n",argv[0]);
                XCloseDisplay(dpy);
                exit(1);
        }

        XkbSelectEvents(dpy, XkbUseCoreKbd, XkbBellNotifyMask, 
XkbBellNotifyMask);

        XkbSetAutoResetControls(dpy, XkbAudibleBellMask, &bit1, &bit2);
        XkbChangeEnabledControls(dpy, XkbUseCoreKbd, XkbAudibleBellMask, 0);

        /* event loop, wait for beeps */
        for(;;){
                XNextEvent(dpy,&event);
                if(event.type == Xkb_event_base &&
                   ((XkbEvent *)&event)->any.xkb_type == XkbBellNotify){
                        fprintf(stderr,"bell!\n");
                }
        }
        XCloseDisplay(dpy);
        return 0;
}



-- 
Nadav Har'El                        |     Wednesday, Dec 7 2005, 6 Kislev 5766
[EMAIL PROTECTED]             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Isn't Disney World a people trap operated
http://nadav.harel.org.il           |by a mouse?

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to