我如何在Windows,Linux和MacOS上确定Python中的显示空闲时间? [英] How can I determine the display idle time from Python in Windows, Linux, and MacOS?

查看:199
本文介绍了我如何在Windows,Linux和MacOS上确定Python中的显示空闲时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道用户上次敲一个键或移动鼠标后多长时间 - 不仅仅是在我的应用程序中,而是整个计算机(即显示器),以便猜测它们是否是仍然在电脑上,并能观察屏幕上弹出的通知。

I would like to know how long it's been since the user last hit a key or moved the mouse - not just in my application, but on the whole "computer" (i.e. display), in order to guess whether they're still at the computer and able to observe notifications that pop up on the screen.

我想纯粹从(Py)GTK +中完成此操作,但我很乐意接受调用平台特定的功能。理想情况下,我想调用已经从Python中包装的函数,但如果这是不可能的,我不会超过一点C或 ctypes 代码,因为只要我知道我真正在寻找什么。

I'd like to do this purely from (Py)GTK+, but I am amenable to calling platform-specific functions. Ideally I'd like to call functions which have already been wrapped from Python, but if that's not possible, I'm not above a little bit of C or ctypes code, as long as I know what I'm actually looking for.

在Windows上,我认为我想要的功能是 GetLastInputInfo ,但似乎没有被pywin32包装;我希望我错过了一些东西。

On Windows I think the function I want is GetLastInputInfo, but that doesn't seem to be wrapped by pywin32; I hope I'm missing something.

推荐答案

Gajim 在Windows,OS X和GNU / Linux(以及其他* nixes)上以这种方式完成它:

Gajim does it this way on Windows, OS X and GNU/Linux (and other *nixes):


  1. Python包装模块(也包括包括Windows空闲时间检测代码,使用 GetTickCount ctypes );

  2. 基于Ctypes的模块获取X11空闲时间(使用 XScreenSaverQueryInfo ,是旧Gajim版本中的C模块);
  3. 获取OS X空闲时间的C模块(使用 HIDIdleTime 系统属性)。

  1. Python wrapper module (also includes Windows idle time detection code, using GetTickCount with ctypes);
  2. Ctypes-based module to get X11 idle time (using XScreenSaverQueryInfo, was a C module in old Gajim versions);
  3. C module to get OS X idle time (using HIDIdleTime system property).

这些链接的版本相当过时,所以你可以希望检查当前的来源是否可能进一步改进和改变。

Those links are to quite dated 0.12 version, so you may want to check current source for possible further improvements and changes.

这篇关于我如何在Windows,Linux和MacOS上确定Python中的显示空闲时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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