简体   繁体   English

ObjC function UCKeyTranslate 可以从 JavaScript 用于自动化吗?

[英]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.

相关问题 使用来自 iOS ObjC 的参数调用 Javascript function - Call Javascript function with parameters from iOS ObjC 在JavaScript for Automation中使用objC bridge Contacts框架 - use objC bridge Contacts framework in JavaScript for Automation 是否可以像在C语言中一样在ObjC中使用函数和函数指针? - Can functions and function pointers be used in ObjC just as they are in C? 使用JavaScript for Automation获得objc_getClassList的类名列表 - Obtaining a list of class names with objc_getClassList in JavaScript for Automation ObjC 中使用的 swift 对象的内存泄漏 - Memory leak with swift object used from ObjC 哪些objc函数用于获取微型化窗口的应用程序图标数据? - What objc function used to get app icon data for miniautrized windows? 将字符串(从objc传递)转换为Javascript中的数组 - Converting String(passed from objc) to Array in Javascript 从 C function 回调访问 ObjC object - Accessing an ObjC object from a C function callback 如何将布尔值从objc(Xcode)返回到Unity或在xCode中执行函数? - How can I return a bool from objc(Xcode) to Unity OR execute a function in xCode? 在Objc中定义的枚举>在Swift中声明>在Objc中使用 - enum defined in Objc > Declared in Swift > to be used in Objc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM