将密钥代码发送到应用程序而不先激活它? [英] Send a key code to an application without activating it first?

查看:112
本文介绍了将密钥代码发送到应用程序而不先激活它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将空格键发送给应用程序,而无需先激活它.以下代码几乎可以实现我想要的功能,但是它首先将应用程序置于前台.

I'm trying to send the spacebar key to an application without activating it first. The following code almost does what I want but it brings the application to the foreground first.

tell application "X"
    activate
    tell application "System Events" to key code 49
end tell

推荐答案

我不认为您可以向非活动应用程序发送击键,但是您可以在激活应用程序并为其执行代码后立即隐藏该应用程序.但是,这确实会导致该应用在隐藏之前短暂闪烁.

I don't think you can send a keystroke to an inactive application, but you can hide an app immediately after activating it and executing code for it. This does however, cause the app to briefly flash before it hides.

tell application "System Events"
    tell application "X" to activate
    key code 49
    set visible of process "X" to false
end tell

这篇关于将密钥代码发送到应用程序而不先激活它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆