Topics

Getting word at cursor position


שמואל רטבי
 

Hello all

I'm trying to build an AddOn which will allows simple phonetic definition of words not correctly pronounced by some synthesizers.

The idea is to have a keyboard event which will trigger the script and return the word under the cursor when pressing the keyboard command. My questions are :

  1. Is there any AddOn that already does something like that and can serve as a basis toe next steps ?
  2. How can I get to retrieve the word containing the caret ?

Note I can easily retrieve the text of the control at focus and the cursor location but I don't find the way to get the word or the characters around the caret. Perhaps "SystemMetrics" can help but I've no idea how to use them.

Help will be very very much appreciated

Shmuel


Alberto Buffolino
 

שמואל רטבי, il 14/02/2021 15.00, ha scritto:
2. How can I get to retrieve the word containing the caret ?
Alberto:
Hi Shmuel,
from console:
t=focus.makeTextInfo(textInfos.POSITION_CARET)
t.expand(textInfos.UNIT_WORD)
t.text
'test'
If focus has treeInterceptor, then it'll be focus.treeInterceptor.makeTextInfo(...)
I don't remember exactly, but if you see strange results in expanding, try to use every time a initial copy (preceeding the expansion) of t object (in my example).
Hth.
Alberto


שמואל רטבי
 

Getting word at cursor
Thanks you a lot, Alberto
Very clear and useful
I'll try that and let you know
Shmuel

-----Original Message-----
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Alberto Buffolino
Sent: Sunday, February 14, 2021 4:33 PM
To: nvda-addons@nvda-addons.groups.io
Subject: Re: [nvda-addons] Getting word at cursor position

שמואל רטבי, il 14/02/2021 15.00, ha scritto:
2. How can I get to retrieve the word containing the caret ?
Alberto:
Hi Shmuel,
from console:
>>> t=focus.makeTextInfo(textInfos.POSITION_CARET)
>>> t.expand(textInfos.UNIT_WORD)
>>> t.text
'test'
If focus has treeInterceptor, then it'll be
focus.treeInterceptor.makeTextInfo(...)
I don't remember exactly, but if you see strange results in expanding,
try to use every time a initial copy (preceeding the expansion) of t
object (in my example).
Hth.
Alberto