首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用rb-appscript键入键盘快捷键

使用rb-appscript键入键盘快捷键
EN

Stack Overflow用户
提问于 2012-04-23 05:26:24
回答 1查看 340关注 0票数 0

我正在尝试使用rb-appscript将以下脚本转换为Ruby:

代码语言:javascript
复制
-- Runs the keyboard shortcut for the provided application name.
-- applicationName - The name of the application to run the keyboard shortcut on.
-- key - The key to press.  For example, this could be "n" or "q".
-- modifiersList - A list of modifiers for the keyboard shortcut.  This could be something like
-- { command down } or { command down, shift down, option down }.
on runKeyboardShortcut(applicationName, key, modifiersList)
    tell application applicationName to activate
    tell application "System Events"
      keystroke key using modifiersList
    end tell
end runKeyboardShortcut

这是我到目前为止所知道的:

代码语言:javascript
复制
def run_keyboard_shortcut(application_name, key, modifiers_list)
    Appscript.app.by_name(application_name).activate
    Appscript.app.by_name("System Events").keystroke(key)
end

如何将修饰符添加到击键命令?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-23 06:17:26

解决方案是这样做:

代码语言:javascript
复制
def run_keyboard_shortcut(application_name, key, modifiers)
    Appscript.app.by_name(application_name).activate
    Appscript.app.by_name("System Events").keystroke(key, :using => modifiers)
end

run_keyboard_shortcut("Finder", "n", [ :command_down ])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10272257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档