Python监控鼠标事件的压枪脚本

本文仅供学习和交流使用,若使用脚本导致游戏封号或其他后果不负一切责任哈~

其实很简单,主要是监控用户的各种操作,之前花了好久在网上找相关库,都是些什么pyhook,pymouse这种的,要求多不实用而且讲道理也不太友好,对环境还有要求,配置测试好久,虽然也可以吧,后来发现还有pynput,一个库功能齐全,果断就放弃前面的了。当然了,需要 pip install pynput 安装一下。

老样子,直接上代码趴~

# coding=utf-8
"""
   吃鸡压枪脚本,可以快速单点可以长按,按backspace退格键开启和关闭
                    ——by Joy
"""
import threading
from pynput.mouse import Button, Listener, Controller
from pynput import keyboard
import time

# 记录操作指令
# 射击
shoot = 0
# 倍镜
scope = -1
# 开启压枪状态
status = 1

# 鼠标控制器
controller = Controller()

"""
鼠标事件
"""
def mouse_click(x, y, button, pressed):
    global shoot
    global scope
    if pressed:
        # 开启倍镜
        if button == Button.right:
            scope = - scope
        # 开始射击
        if button == Button.left:
            shoot = 1
    # 结束射击
    if not pressed and button == Button.left:
        shoot = 0

# 监控鼠标位置
def mouse_move(x, y):
    print x, y

"""
键盘事件
"""
def keyboard_release(key):
    global status
    if key == keyboard.Key.backspace:
        # 更改压枪状态
        status = -status
"""
监听事件方法
"""
def mouseListener():
    with Listener(on_click=mouse_click, on_move=mouse_move) as listener:
        listener.join()

def keyboardListener():
    with keyboard.Listener(
            on_release=keyboard_release) as listener:
        listener.join()

def main():
    threading._start_new_thread(mouseListener, ()) 
    threading._start_new_thread(keyboardListener, ())
    # 循环监听各状态并控制鼠标
    while 1:
        if shoot == 1 and scope == -1 and status == 1:
            time.sleep(0.2) # 根据一般的子弹射速有节奏的压枪
            controller.move(0, +15)
        elif shoot == 1 and scope == 1 and status == 1:  # 开启倍镜,增加压枪幅度
            time.sleep(0.2)
            controller.move(0, +25)


if __name__ == '__main__':
    main()

运行脚本测试是OK的,不过没进游戏试过怕被封,233333


猜你喜欢

转载自blog.csdn.net/qq_35221523/article/details/79324653