[other] 解放食指
Tofloor
poster avatar
fozei
deepin
2023-11-28 22:46
Author

最近食指疼的厉害,在AI的帮助下,写了一段鼠标移动后自己点击左键的小脚本。

  1. 在命令行中使用 python3 autoclick.py执行程序,别关命令行窗口。
  2. 在按一下ESC键开启或者关闭功能
  3. 在开启、关闭和执行点击时播放了系统提示音
  4. 求高手:能否给点击时,调用系统API,在桌面上绘制涟漪效果?

代码仓库地址:代码仓库

代码如下:

import subprocess
from pynput import mouse, keyboard
import pyautogui
from threading import Timer

# 设置定时器时间间隔为0.5秒
interval = 0.2

# 定义一个变量来存储定时器对象
timer = None
working = False

from_click = False

def on_press(key):
    global working
    if key == keyboard.Key.esc:  
        working = not working
        play_sound("/usr/share/sounds/freedesktop/stereo/window-attention.oga")
        print("+++++开启+++++" if working else "-----关闭-----" )

def on_move(x, y):
    global timer, working

    # 如果是程序引起的移动,或者未开启程序,则不处理
    if not working or from_click:
        return
    # 如果之前有定时器,取消
    if timer and timer.is_alive():
        timer.cancel()

    timer = Timer(interval, do_click)
    timer.start()

def do_click():
    global from_click
    from_click = True
    pyautogui.click()
    play_sound("/usr/share/sounds/freedesktop/stereo/audio-volume-change.oga")
    from_click = False

def play_sound(path):
    subprocess.call(["sox", path,"-d"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)  # 播放Linux系统默认提示声音  


# 创建键盘listener并注册回调函数
keyboard_listener = keyboard.Listener(on_press=on_press)
keyboard_listener.start()

# 创建鼠标listener并注册回调函数
mouse_listener = mouse.Listener(on_move=on_move)

# 启动鼠标listener
mouse_listener.start()

print("按 esc 开启/关闭" )
# 让程序保持运行状态
mouse_listener.join()

Reply Favorite View the author
All Replies
jjcui8595
deepin
2023-11-29 00:03
#1

like

弱弱地问一句,设置鼠标左手模式是不是就解放了食指?

Reply View the author
Amber
deepin
2023-11-29 02:13
#2
jjcui8595

like

弱弱地问一句,设置鼠标左手模式是不是就解放了食指?

无名指:6joy

Reply View the author
阿尼樱奈奈
Moderator
2023-11-29 02:38
#3

like joy

Reply View the author
fozei
deepin
2023-11-29 18:42
#4
It has been deleted!