在我的 python 脚本中,我必须确定实际的活动窗口/应用程序以对依赖于远程事件(lirc)的应用程序做出反应。所以我试着像这里描述的那样重新定义它。但是测试代码
import wnck, time
run = True
while run:
try:
time.sleep(1)
screen = wnck.screen_get_default()
#screen.force_update()
print screen.get_active_window().get_name()
print screen.get_previously_active_window()
except KeyboardInterrupt:
run = False
导致此输出
.lirc : python — Konsole
None
.lirc : python — Konsole
None
.lirc : python — Konsole
None
.lirc : python — Konsole
None
.lirc : python — Konsole
None
即使我切换到另一个窗口。因此我重复了执行并延迟了它time.sleep(1)
。由远程事件 (lirc) 执行,结果是相同的。只有在 python shell 中它才能工作(有screen.get_previously_active_window()
/ 正确的结果)。该脚本已在 Kubuntu 16.04 的终端窗口 (konsole) 中执行。我已经测试过 insert screen.force_update()
,但没有成功。
我做错了什么?
谢谢