The function CGEventKeyboardSetUnicodeString takes a UniCharCount and const UniChar unicodeString[]. I am having trouble figuring out how I can call this from python using pyobjc. Ideally, I'd like to be able to just pass in a python unicode string. Is there a way to modify the metadata for this function so I can do that? Alternatively, is there a way for me to convert a python unicode string into an array of UNICHAR and a length using pyobjc?
To clarify:
I am using version 2.5.1 of pyobjc
the metadata of CGEventKeyboardSetUnicodeString:
>>> pprint(CGEventKeyboardSetUnicodeString.__metadata__())
{'arguments': ({'already_cfretained': False,
'already_retained': False,
'null_accepted': True,
'type': '^{__CGEvent=}'},
{'already_cfretained': False,
'already_retained': False,
'type': 'L'},
{'already_cfretained': False,
'already_retained': False,
'null_accepted': True,
'type': '^T'}),
'retval': {'already_cfretained': False,
'already_retained': False,
'type': 'v'},
'variadic': False}
I've tried the following:
>>> CGEventKeyboardSetUnicodeString(event, 1, 'a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: depythonifying 'pointer', got 'str'
>>> CGEventKeyboardSetUnicodeString(event, 1, u'a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: depythonifying 'pointer', got 'unicode'
>>> CGEventKeyboardSetUnicodeString(event, 1, [ord('a')])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: depythonifying 'pointer', got 'list'
>>> Quartz.CGEventKeyboardSetUnicodeString(event, 1, struct.unpack('>{}H'.format(1), u'a'.encode('utf-16-le')))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: depythonifying 'pointer', got 'tuple'