如何使用Python控制键盘和鼠标? [英] How can I control the keyboard and mouse with Python?

查看:492
本文介绍了如何使用Python控制键盘和鼠标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Python中控制鼠标和键盘?

How can I control the mouse and keyboard in Python?

该想法与 Robot()类.可以说:将鼠标从此处移至此处,单击此处,然后将其写在屏幕上.

The idea is to do the same as the Robot() class in Java. Be able to say: move the mouse from here to here, click there, write that whatever is on the screen.

对于Windows,有win32api,但我主要使用Linux.

For Windows there is win32api but I'm using mainly Linux.

对于Linux,有Xlib,但它也可用于键盘吗? (仅找到对鼠标的引用)

For Linux there is Xlib but does it works for keyboard as well? (found only reference to the mouse)

是否存在跨平台解决方案? (Linux,Windows甚至OS X都很棒.)

Is there a cross-platform solution? (Linux, Windows and even OS X would be the great.)

推荐答案

对于鼠标,我发现

for the mouse, I've found pymouse which seems to work (I haven't fully tried it, a small hack needed for the click, cf the issues)

对于键盘,我不确定Xlib是否可以完成这项工作.我仍在寻找如何编写内容的方法,但是您可以按照此处或使用Xlib在C 此处但我不知道C).

for the keyboard, I'm not sure Xlib can do the job. I'm still looking on how to write something but you can catch key event as explained here or in C here using Xlib (but I don't know C).

此处是使用gnome的示例仅(还不够好)

here is an example working on gnome only (not good enough yet)

在pymouse中,他们有一种很好的方法可以使其在3个不同的平台上工作,但需要编写3个代码...

In pymouse, they have a nice way to make it work on the 3 different platform but needs to make 3 code...

这篇关于如何使用Python控制键盘和鼠标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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