鼠标持续点击

最近玩一款老游戏, 里面开箱子太麻烦了, 一直手动点, 朋友让我试着写一个脚本。 就搜了下, 挺好实现的, 就试着写出来了。

修改下 也可以做些其他重复的事情。  

其实就是一个x键精灵的事情大笑


我的系统是 win7 64, python34

用到了pyhooked,pypiwin32


pyhook我一直安不上,就用的pyhooked,win32,可以直接用pip install pypiwin32安装。


from pyhooked import Hook, KeyboardEvent, MouseEvent
import win32gui, win32con, win32api
import time
from ctypes import *

import threading


def mouse_click(x=None, y=None):
    if not x is None and not y is None:
        mouse_move(x, y)
        time.sleep(0.05)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)


def mouse_dclick(x=None, y=None):
    if not x is None and not y is None:
        mouse_move(x, y)
        time.sleep(0.05)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)


def mouse_move(x, y):
    windll.user32.SetCursorPos(x, y)


class MyThread(threading.Thread):
    def __init__(self, timesleep=0.15):
        super(MyThread, self).__init__()
        self.stopped = False
        self.timesleep = timesleep

    def run(self):
        print('启动')
        x, y = win32gui.GetCursorPos()
        count = 0
        while not self.stopped:
            count += 1
            mouse_click(x, y)
            time.sleep(self.timesleep)
        print('本次点击了%s次' % count)

    def stop(self):
        self.stopped = True
        print('停止')

    def isStopped(self):
        return self.stopped


class MyHook(Hook):
    def __init__(self):
        Hook.__init__(self)
        self.open = False
        self.thread = None

    def handle_events(self, args):
        if isinstance(args, KeyboardEvent) and not self.open and args.current_key == 'F2' and args.event_type == 'key down':
            self.thread = MyThread()
            self.thread.start()
            self.open = True

        elif isinstance(args,KeyboardEvent) and self.open and args.current_key == 'F2' and args.event_type == 'key down':
            self.open = False
            self.thread.stop()
            time.sleep(1)


if __name__ == '__main__':
    print('F2启动,再次F2关闭,启动时请不要移动鼠标')
    hk = MyHook()  # make a new instance of PyHooked
    hk.handler = hk.handle_events  # add a new shortcut
    hk.hook()  # hook into the events, and listen to the presses


参考 :http://www.jb51.net/article/47422.htm

自动鼠标点击工具,完全免费版 AutoMouseClicker - No more trembling fingers! Version 2.2 for Windows 9x/NT/2K/ME/XP http://www.geocities.com/mangokun/ !!! You MUST put the files below together in the same folder. AutoMouseClicker.exe AutoMouseClicker.txt config.xml (will be created if not found) events.xml (can be created if not found) .\IconThemes\*.* What Some irritating games or softwares requires you to click many hundred times, and this program just do that for you automatically. New Features: AutoMouseClicker 2 is back with more amazing features! - click interval now works correctly, with a countdown displayed - random intervals (between 2 values) - loop mouse events (highly-requested!) - save loop value together with the mouse events to XML - turn on XP Visual Styles (which "normal" applications doesn't provide support for) - system tray (deactivated by default) - customizable tray icons (through icon themes) - control multiple instances with single hotkey Features: - keep the program 'Always on Top' of all other windows (Useful) - keep your program settings (in a XML file) - clicks the Left or Right mouse button automatically - HotKey lets you start/stop the auto-clicking (useful with Hyper-Click) - Hyper-Click option clicks the position where you have moved your mouse pointer to - RepeatClick textfield can be reset to the initial value entered when the clicking stops - start program minimized (useful to combine with autoSTART) - programmable mouse events - Saving/Loading of events to XML format (editable manually) - Command Line Argument(s) - run: automatically starts clicking - works as long as the word run is added to end of command line, - doesn't matter if run is preceded by a -run or /run - to run on windows startup, just put a shortcut ["AutoMouseClicker.exe" -run] in the windows Startup folder - load or event: automatically loads events.xml (meaning you can virtually set everything up, and make a shortcut to trigger a series of mouse clicks, with AutoMouseClicker's windows set to minimized!) - terminate: automatically terminates program after clicking stopped. Here's an example: "C:\AutoMouseClicker\AutoMouseClicker.exe" load run terminate What it simply means: AutoMouseClicker will start, load and run events.xml, then terminates.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值