[英]Can the ObjC function UCKeyTranslate be used from JavaScript for Automation?
In an osascript/JXA context, I need to map macOS keyCodes and modifiers to Unicode strings (for any keyboard layout, specified at run-time)在 osascript/JXA 上下文中,我需要 map macOS keyCodes 和修饰符到 Unicode 字符串(对于任何键盘布局,在运行时指定)
The obvious candidate appears to be UCKeyTranslate
, but my attempts to get a reference to it from a JavaScript for Automation context have not been successful so far.明显的候选者似乎是
UCKeyTranslate
,但到目前为止,我试图从 JavaScript 的自动化上下文中获取对它的引用尚未成功。
Does anybody know how to do this, perhaps in terms of ObjC.bindFunction
?有谁知道如何做到这一点,也许就
ObjC.bindFunction
?
One way to go would be to make a Swift or ObjC helper library (or a command line tool), and then use that from JXA. go 的一种方法是制作 Swift 或 ObjC 帮助程序库(或命令行工具),然后使用 JXA 中的那个。 Check some example code to start .
检查一些示例代码以开始。
If you wrap this call in an ObjC object method inside a framework, it's possible to ObjC.import()
it and use in your scripts.如果您将此调用包装在框架内的 ObjC object 方法中,则可以将其
ObjC.import()
并在您的脚本中使用。 If you choose to do a command line app, then call it as a shell command.如果您选择执行命令行应用程序,则将其称为 shell 命令。
Using ObjC.bindFunction seems a bit too complicated, because you'd have to bind a few other functions that would get you a UCKeyboardLayout instance, and define a bunch of magic constants, plus do some necessary mapping of strings and pointers.使用 ObjC.bindFunction 似乎有点过于复杂,因为您必须绑定一些其他函数,这些函数将为您提供 UCKeyboardLayout 实例,并定义一堆魔术常量,以及对字符串和指针进行一些必要的映射。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.