[BRLTTY] how to use readKey on Windows
James Teh
jamie at jantrid.net
Wed Nov 26 17:58:22 EST 2008
On 27/11/2008 4:30 AM, Thijs Koerselman wrote:
> 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.
This won't work. If you call readKey in another thread like this (at
least on Windows), any other calls to BRLAPI (e.g. to write text to the
display) will block. I *think* this is because you can't have two
operations occurring simultaneously on the same bidirectional pipe. This
does make some sense.
The solution I used in NVDA was to set up a timer in my main thread to
poll for keys. This also avoids the need to spawn another thread.
Another gotcha you should be aware of is that if you write to the
display while there are keys waiting to be read, the write operation
will block (and thus your application will hang). This is because
Windows local named pipes (which BRLAPI uses) don't queue input. This
issue is a bug in the Windows implementation of BRLAPI, but for the
aforementioned reason, it is very difficult to solve; the brlapi server
would need to do its own queuing. To get around this, you need to read
all keys before each write. There is still a possible race condition
here, but it usually won't occur.
--
James Teh
Email/MSN Messenger/Jabber: jamie at jantrid.net
Web site: http://www.jantrid.net/
More information about the BRLTTY
mailing list