Simulate Mouse Clicks on Python

2019-02-02 07:12发布

I'm currently in the process of making my Nintendo Wiimote (Kinda sad actually) to work with my computer as a mouse. I've managed to make the nunchuk's stick control actually move the mouse up and down, left and right on the screen! This was so exciting. Now I'm stuck.

I want to left/right click on things via python when I press A, When I went to do a search, All it came up with was tkinter?

So my question is, What do I call to make python left/right click on the desktop, and if it's possible, maybe provide a snippet?

Thank you for your help!

NOTE: I guess I forgot to mention that this is for Linux.

9条回答
我想做一个坏孩纸
2楼-- · 2019-02-02 07:38

PyAutoGui works superb.. Thanks to Al Sweigart...

An example of mine...

import pyautogui

pyautogui.FAILSAFE = False

for x in range(555, 899):
    pyautogui.moveTo(x, x)
查看更多
Explosion°爆炸
3楼-- · 2019-02-02 07:39

The evdev package provides bindings to parts of the input handling subsystem in Linux. It also happens to include a pythonic interface to uinput.

Example of sending a relative motion event and a left mouse click with evdev:

from evdev import UInput, ecodes as e

capabilities = {
    e.EV_REL : (e.REL_X, e.REL_Y), 
    e.EV_KEY : (e.BTN_LEFT, e.BTN_RIGHT),
}

with UInput(capabilities) as ui:
    ui.write(e.EV_REL, e.REL_X, 10)
    ui.write(e.EV_REL, e.REL_Y, 10)
    ui.write(e.EV_KEY, e.BTN_LEFT, 1)
    ui.syn()
查看更多
Explosion°爆炸
4楼-- · 2019-02-02 07:39

you might find this helpful:

http://www.eventghost.org/

Good luck!

查看更多
登录 后发表回答