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

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

问题描述

我试图将空格键发送到应用程序而不先激活它.下面的代码几乎完成了我想要的,但它首先将应用程序带到了前台.

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天全站免登陆