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


Jacob Kruger
 

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.