Re: Next couple of questions relating to retrieving an object based on controlID, performing actions, typing in text automatically and event binding


Travis Roth
 

Hi Jacob,

 

As for your questions:

  1. myObj = NVDAObjects.IAccessible.getNVDAObjectFromEvent(

        windowUtils.findDescendantWindow(api.getForegroundObject().windowHandle, controlID=xxx),

                winUser.OBJID_CLIENT, 0)

where xxx is the desired control id. (As posted by Jamie some years ago.)

 

  1. Sorry I don’t understand that question.
  2. I suspect this comes down a lot to your needs, purpose and preference. The one annoying thing about applications that use the clipboard is they overwrite things I already had on the clipboard, and if I don’t realize this is how they operate, poof there goes my last clipboard entry.
  3. I think you’re looking for chooseNVDAObjectOverlayClasses and then you’ll need to make a custom class that defines your event. See the addons developer guide, it explains a lot better than I ever could.

Travis

From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Jacob Kruger
Sent: Wednesday, January 13, 2021 3:20 AM
To: NVDA-Addons <nvda-addons@nvda-addons.groups.io>
Subject: [nvda-addons] Next couple of questions relating to retrieving an object based on controlID, performing actions, typing in text automatically and event binding

 

Me, again - few different questions, and, will number them for reference.

 

1. Ok, firstly, if I have the controlID for a GUI element on record - presume these stay the same across sessions, most of the time - then, how would I retrieve an instance of an NVDA object based on this controlID?

 

As in, is this doable?

 

What I mean is, could I use the controlID value to retrieve an object similar to what gets retrieved by api.getNavigatorObject() an api.getFocusObject(), or is there some other preferred method for retrieving instances of specific objects?

 

2. Secondly, presume that depending on the type of element, the obj.doAction() function will do something like perform a mouse-click on a button/menu item, or open up a drop-down, and, obj.setFocus() would, obviously, do something like set focus to a text entry field?

 

3. If I want to automate forms of text entry, I can use something like api.copyToClip(), followed by emulating a ctrl+V keystroke, but, would it be better to rather do something like the following, for example, to type in a single character, almost as if the user was doing it themselves?

 

gesture = keyboardHandler.KeyboardInputGesture.fromName("a")

inputCore.manager.emulateGesture(gesture)

 

As in, the above two lines of code do seem to enter the letter a into a text field, but, if a menu had focus, would it then more or less perform the keypress of the letter a, to then possibly activate a sub-menu, or menu item bound to the letter a?

 

If I then used something like the above two lines of code to enter a single character, but, wanted to enter a whole string, would this then still be the best way to handle it, using a form of loop through the whole string to be entered, or should I then use a different method/means, or use the clipboard approach?

 

4. How simple is it to, at run time, bind an event to a specific element, again based on something like a controlID, or would this need to be included in code before-hand, and if so, what's the specific syntax for that?  As in, do I perform a check against controlID or name before then executing code, based on the event_ syntax - purely a sample here:

def event_gainFocus(self, obj, nextHandler):

  if obj.windowControlID=="1234567890":

    #do something here

 

Thanks for any feedback

Jacob Kruger
+2782 413 4791
Skype: BlindZA
"...resistance is futile...but, acceptance is versatile..."

Join nvda-addons@nvda-addons.groups.io to automatically receive all group messages.