[BRLTTY] how to use readKey on Windows

Thijs Koerselman thijskoerselman at gmail.com
Wed Nov 26 13:30:35 EST 2008


Hi all,

For a week I didn't have access to the braille bar, so development was on
halt. Now I am trying to finish up what I was doing but I seem to be stuck
on something again.

Brltty is working fine with the command line stuff. From my app I can
successfully connect to the brlapi and call enterTty and such. The problem
lies with readKey(). When I call this method (telling it to wait for key
input), most of the time it results in my app hanging because no key is ever
returned. The weird thing is that this doesn't seem to be consistent. It
worked a number of times, and mostly it doesn't. Software which sometimes
works and sometimes doesn't, while I can't find any difference, makes me
feel I'm going crazy.

I am wondering if I'm taking the right approach. My plan was to spawn a new
thread from my main app. This thread then calls readKey() in an infinite
loop (as long as some flag is valid). The keys returned by brlapi are
buffered, and my main app is reading this buffer at fixed intervals.

Just to be sure I'm not doing something incredibly stupid I posted some code
of a simple test method below. It connects to the brlapi and waits for a
single key to be pressed. This is already going wrong 95% of the time. In my
polling loop I wouldn't reconnect to the brlapi for every keystroke of
course.

How is this kind of thing done with NVDA?

I really hope someone can point me in the right direction. I need to get
this thing up and running as soon as possible.

I'm using 3.10-12

Cheers,
Thijs


void MyClass::fetchFoo()
{
    // Connect to BrlAPI
    if (brlapi_openConnection(NULL,NULL)<0){
        error("brlapi_openConnection");
        return;
    }

    // Get tty control
    post("Taking control of the tty... ");
    if (brlapi_enterTtyMode(BRLAPI_TTY_DEFAULT, NULL)<0){
        error("brlapi_enterTtyMode");
        goto connection;
    }

    post("Ok");

    brlapi_keyCode_t key;

    // Wait for a key press
    post("Waiting until a braille key is pressed to continue... ");
    if (brlapi_readKey(1,&key)>0)
        post("got it! (code=%"BRLAPI_PRIxKEYCODE")",key);
    else
        error("brlapi_readKey");

    // Leave tty control
    post("Leaving tty... ");
    if (brlapi_leaveTtyMode()<0){
        error("brlapi_leaveTtyMode");
    }

    post("Ok");

connection:
    // Disconnect from BrlAPI
    brlapi_closeConnection();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mielke.cc/pipermail/brltty/attachments/20081126/a6440511/attachment.html 


More information about the BRLTTY mailing list