Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting NSString to keyCode+modifiers for AXUIElementPostKeyboardEvent
    text
    copied!<p>Edit: Turns out, I was misled during my initial explorations of the accessibility APIs. Once I found the secure text field in the AX hierarchy, I was easily able to set the value. Not sure what to do with this question beyond that, but I wanted to update this for future searchers.</p> <p>I'm working on some code that will post keyboard events to targeted applications using the Accessibility APIs. So far, I have been able to write a trivial app that allows me to type in a string value and then post keyboard events with those key codes to the targeted application. In reality, the strings would be read from another location.</p> <p>What I have not yet been able to figure out is how to ascertain whether and which modifier keys should also be posted. For instance, when I type <code>Hello, world!</code> into my test application, the input is sent to the other application as <code>hello, world1</code> because I am not yet including the modifier keys to create the upper case H and the exclamation point. This is made doubly complicated by multi-keystroke characters like <code>é</code> or <code>ü</code>. Sending <code>é</code> sends a raw <code>e</code> with no accent for example.</p> <p>Is there a simple method I am overlooking for discerning the modifiers to combine with a keycode for creating a particular NSString or unichar? If not, does anyone have a suggestion of how to proceed? So far, the best I have come up with is calling <code>UCKeyTranslate</code> with all possible modifier combinations until I find one that matches the <code>unichar</code> I get using <code>-[NSString characterAtIndex:]</code> I'm not sure this is scalable or reliable, though, given the multi-keystroke nature of some characters as noted above.</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload