I am developing a game with swing and I would like to display some information when a key is pressed, for instance the health of the character. Is there a way in which a screen reader could read this information without moving the focus and therefore interrupting the game? Thank you in advance.
AS a blind person myself, I can effectively confirm that, it's better to make the screen reader speak rather than using a separate TTS engine. The advantages include:
When using a separate TTS engine, the voice used can dramatically differ from user settings, and in particular, can be speaking in the wrong language, far too slow, or far too fast.
ON the web, making the screen reader speak some text is achieved with ARIA live region
For a desktop or native application, basically, there exist as many different API as there are screen readers. There is no common standard at all. You must detect the screen reader used if any, and then communicate with it using its specific API.
Fortunately, there are library which helps you doing that:
Note that several UI toolkits for desktop/native applications also implement something quite similar to ARIA live regions. If the text to be spoken has also to be displayed in the same time, you should preferably use that rather than libraries listed above. It is supported by all reasonably recent screen readers. Note that, ARIA live regions and similar systems are usually slightly slower than calling screen readers API directly though; it may be significant for a game.