matlab:鼠标循环点击器

时间:2022-12-20 18:52:00

1. 简介

采集PC端一个或是多个点的位置坐标,对这些位置可以按照次序循环点击。(之前玩阴阳师的时候,开发了这个用来刷各种资源。现在把它开源,希望更多人可以用来做更多的事情)

matlab:鼠标循环点击器


2. 使用说明

板块1·采点

板块作用

根据鼠标所在的位置采集坐标,然后自动以当前的时间命名显示在历史数据的第一行。

名称解释

数量:预备采集点的数目
间隔:采集相邻两个点之间的间隔时间(单位:秒,其它与时间有关的单位均是秒)
延时:从点击采点板块中的“开始”之后到采集第一个点坐标的时间。
开始:开始采集


板块2·坐标

板块作用

显示所采集的坐标,也可以再做修改

名称解释

删除:设置要删除的编号后,删除该点的坐标。


板块3·历史数据

板块作用

选择要循环的数据。

名称解释

删除:鼠标选中数据后,通过此按钮进行删除操作。
恢复:恢复上一个删除的数据。
重命名:鼠标选中数据,在左栏中输入名称后,更新命名。


板块4·循环点击

板块作用

执行循环点击操作。

名称解释

次数:循环点击的次数
间隔:每两个位置点之间点击的时间间隔。(该间隔可以设置的很小,但是实际下限和电脑cpu算力有关,极限大约是每秒数千次点击)
延时:点击本板块的“开始”之后到第一次点击之间的时间间隔。
随机扰动:勾选后,真实的点击位置落在预设点的周围,但是距离非常近,而且在循环中每一次位置都不相同。
存在漂移:如果不需要追求巅峰点击频率,直接勾选;否则的话,建议使用之前,先做一下测试,看看所使用的电脑存不存在漂移现象。测试办法:采集一个点的位置,循环点击100次。如果光标在循环初期不断移动,而后逐渐稳定在既定位置,则是存在漂移现象,需要勾选;如果光标始终停留在既定的位置,则不存在漂移,不需要勾选。(是否会发生漂移和电脑的具体型号有关,似乎是好一些的电脑不太容易发生漂移,似乎是)
开始:开始循环点击。


3. 附注

  • 如果点击的对象是其它应用,务必以管理员模式运行matlab
  • .p和程序源码只在matlab2021及2022的版本上进行过测试,更早期的版本暂不支持。

4. 程序包

链接:https://pan.baidu.com/s/13Y6bFgaADCzolv6fqB3IHQ
提取码:yk66


5. 程序源码

classdef auto_mouse < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure          matlab.ui.Figure
        Label_10          matlab.ui.control.Label
        Hyperlink         matlab.ui.control.Hyperlink
        Lamp              matlab.ui.control.Lamp
        Label_4           matlab.ui.control.Label
        Panel_2           matlab.ui.container.Panel
        CheckBox_2        matlab.ui.control.CheckBox
        CheckBox          matlab.ui.control.CheckBox
        EditField_7       matlab.ui.control.NumericEditField
        Label_6           matlab.ui.control.Label
        EditField_5       matlab.ui.control.NumericEditField
        Label_3           matlab.ui.control.Label
        EditField_4       matlab.ui.control.NumericEditField
        EditField_4Label  matlab.ui.control.Label
        Button_3          matlab.ui.control.StateButton
        Panel             matlab.ui.container.Panel
        EditField_6       matlab.ui.control.NumericEditField
        Label_5           matlab.ui.control.Label
        EditField_2       matlab.ui.control.NumericEditField
        Label_2           matlab.ui.control.Label
        EditField         matlab.ui.control.NumericEditField
        Label             matlab.ui.control.Label
        Button            matlab.ui.control.StateButton
        Panel_3           matlab.ui.container.Panel
        Label_8           matlab.ui.control.Label
        EditField_3       matlab.ui.control.NumericEditField
        Button_8          matlab.ui.control.StateButton
        UITable           matlab.ui.control.Table
        Panel_4           matlab.ui.container.Panel
        Button_6          matlab.ui.control.Button
        EditField_8       matlab.ui.control.EditField
        Button_5          matlab.ui.control.StateButton
        Button_4          matlab.ui.control.StateButton
        ListBox           matlab.ui.control.ListBox
        Image             matlab.ui.control.Image
    end

    
    properties (Access = private)
        Core_data % Description
    end
    

    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app)
    
            addpath (pwd)
            app.Image.ImageSource = 'vsgif_com__.3078288.gif'; % 加载图片
            try
                load data0.mat  % 加载历史数据
            catch
                data = [{'无历史数据'},{''}];
                save data0.mat data
            end

            
            if isempty(data)
                data = [{'无历史数据'},{''}];
            end
            app.ListBox.Items =  data(:,1); % 设置选择框  
        end

        % Value changed function: Button
        function ButtonValueChanged(app, event)
            app.Lamp.Color = [0,1,0];
            pause(app.EditField_6.Value)
            import java.awt.Robot 
            import java.awt.event.*
            import java.awt.MouseInfo
            N = app.EditField.Value ;        % 关键点数
            core = zeros(N,2);
            for i = 1:N
                o = MouseInfo.getPointerInfo().getLocation();
                core(i,1) = o.getX();
                core(i,2) = o.getY();
                f = msgbox(['(',num2str(core(i,1)),',',num2str(core(i,2)),')','采集完成']);
                pause(0.4)
                close (f)
                pause(app.EditField_2.Value)
            end
            app.Core_data = core;
            app.UITable.Data = [(1:N)',core];
            s = uistyle('HorizontalAlignment','center');  % 居中
            addStyle(app.UITable,s,'table','');
            load data0.mat
            s = cell(1,2);
            s(1,1) = {datestr(now,'yyyy-mm-dd HH:MM:SS')};
            s(1,2) = {app.Core_data};
            if strcmp(data{1,1},'无历史数据')
                data = s;
            else
                data = [s;data];
            end
            app.ListBox.Items = data(:,1); % 设置选择框
            save data0.mat data
            app.ListBox.Value = data(1,1);
            app.Lamp.Color = [1,1,1];
        end

        % Callback function
        function Button_2ValueChanged(app, event)
            if app.EditField_3.Value > 0 && app.EditField_3.Value <= size(app.UITable.Data,1)
                app.UITable.Data(app.EditField_3.Value,:) = [];
                app.UITable.Data(:,1) = (1:size(app.UITable.Data,1))';
            end
        end

        % Value changed function: EditField_3
        function EditField_3ValueChanged(app, event)
            uistack(app.EditField_3,'top')
            app.Label_8.delete
        end

        % Value changed function: Button_3
        function Button_3ValueChanged(app, event)
            app.Lamp.Color = [0,1,0];
            pause(app.EditField_7.Value);
            import java.awt.Robot 
            import java.awt.event.*
            robot = Robot;
            load data0.mat
            if strcmp (app.ListBox.Value,"无历史数据") && isempty(app.UITable.Data)
                app.Label_10.Text = '还没设置坐标呢';
                app.Lamp.Color = 'red';
                pause (5)
                app.Label_10.Text = '';
                app.Lamp.Color = [1,1,1];
            else
                if ~strcmp (app.ListBox.Value,"无历史数据")
                    core = data{strcmp(data,app.ListBox.Value),2};
                else
                    core = app.UITable.Data(:,2:3);
                end
                tic
                if app.CheckBox_2.Value == 1
                    kk = 200;
                else
                    kk = 1;
                end
                if app.CheckBox.Value == 1
                    for i = 1:app.EditField_5.Value
                        for j = 1:size(core,1)
                            rand1 = rand*3;
                            for k = 1:kk
                                robot.mouseMove(core(j,1)+rand1,core(j,2)+rand1);
                            end
                            robot.mousePress(InputEvent.BUTTON1_MASK);
                            robot.mouseRelease(InputEvent.BUTTON1_MASK);
                            pause(app.EditField_4.Value)
                        end
                    end
                else
                    for i = 1:app.EditField_5.Value
                        for j = 1:size(core,1)
                            for k = 1:kk
                                robot.mouseMove(core(j,1),core(j,2));
                            end
                            robot.mousePress(InputEvent.BUTTON1_MASK);
                            robot.mouseRelease(InputEvent.BUTTON1_MASK);
                            pause(app.EditField_4.Value)
                        end
                    end
                end
                toc
                pause(0.2)
                app.Lamp.Color = [1,1,1];
            end
        end

        % Value changed function: EditField_2
        function EditField_2ValueChanged(app, event)
            value = app.EditField_2.Value;
            if value <= 0
                app.EditField_2.Value = 1;
            end
        end

        % Value changed function: EditField
        function EditFieldValueChanged(app, event)
            value = app.EditField.Value;
            if value < 1
                app.EditField.Value = 1;
            else 
                app.EditField.Value = round(value);
            end


        end

        % Value changed function: EditField_5{12}
        function EditField_5ValueChanged(app, event)
            value = app.EditField_5.Value;
            if value < 1
                app.EditField_5.Value = 1;
            else 
                app.EditField.Value = round(value);
            end
        end

        % Value changed function: EditField_4
        function EditField_4ValueChanged(app, event)
            value = app.EditField_4.Value;
            if value <= 0
                app.EditField_4.Value = 1;
            end
        end

        % Value changed function: EditField_6
        function EditField_6ValueChanged(app, event)
            value = app.EditField_6.Value;
            if value < 0
                app.EditField_6.Value = 0;
            end
        end

        % Value changed function: EditField_7
        function EditField_7ValueChanged(app, event)
            value = app.EditField_7.Value;
            if value < 0
                app.EditField_7.Value = 0;
            end
        end

        % Value changed function: Button_4
        function Button_4ValueChanged(app, event)
            app.Lamp.Color = [0,1,0];
            load data0.mat
            save data1.mat data
            data(strcmp(data,app.ListBox.Value),:) = [];
            if isempty(data)
                data = [{'无历史数据'},{}];
            end
            save data0.mat data
            app.ListBox.Items =  data(:,1);
            pause(0.2)
            app.Lamp.Color = [1,1,1];
        end

        % Value changed function: Button_5
        function Button_5ValueChanged(app, event)
            app.Lamp.Color = [0,1,0];
            load data1.mat
            app.ListBox.Items = data(:,1);
            save data0.mat data
            pause(0.2)
            app.Lamp.Color = [1,1,1];
        end

        % Button pushed function: Button_6
        function Button_6Pushed(app, event)
            app.Lamp.Color = [0,1,0];
            load data0.mat
            data(strcmp(data,app.ListBox.Value),1) = {app.EditField_8.Value};
            save data0.mat data
            app.ListBox.Items =  data(:,1);
            pause(0.2)
            app.Lamp.Color = [1,1,1];
        end

        % Callback function: not associated with a component
        function Button_7ValueChanged(app, event)
            app.Lamp.Color = [0,1,0];
            load data0.mat
            s = cell(1,2);
            if isempty(app.EditField_9.Value)
                s(1,1) = {datestr(now,'yyyy-mm-dd HH:MM:SS')};
            else
                s(1,1) = {app.EditField_9.Value};
            end
            s(1,2) = {app.Core_data};
            if strcmp(data{1,1},'无历史数据')
                data = s;
            else
                data = [s;data];
            end
            app.ListBox.Items = data(:,1); % 设置选择框
            save data0.mat data
            pause(0.2)
            app.Lamp.Color = [1,1,1];
%             app.Button_7.BackgroundColor = [1,1,1];
        end

        % Value changed function: Button_8
        function Button_8ValueChanged(app, event)
            app.Lamp.Color = [0,1,0];
            if app.EditField_3.Value > 0 && app.EditField_3.Value <= size(app.UITable.Data,1)
                app.UITable.Data(app.EditField_3.Value,:) = [];
                app.UITable.Data(:,1) = (1:size(app.UITable.Data,1))';
            end
            pause(0.2)
            app.Lamp.Color = [1,1,1];
        end

        % Callback function: not associated with a component
        function EditField_9ValueChanging(app, event)
%             changingValue = event.Value;
            app.Label_9.delete
        end

        % Image clicked function: Image
        function ImageClicked(app, event)
            if rand < 0.7
                app.Label_10.Text = '你在点些什么?';
                pause(5)
                app.Label_10.Text = '';
            elseif rand <0.95
                app.Label_10.Text = '忙忙碌碌的,要去哪?';
                pause(5)
                app.Label_10.Text = '';
            elseif rand>=0.95
                app.Label_10.Text = '要记得常看看风景';
                pause(5)
                app.Label_10.Text = '';
            end
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Get the file path for locating images
            pathToMLAPP = pwd;

            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Color = [1 1 1];
            app.UIFigure.Position = [100 100 640 578];
            app.UIFigure.Name = '鼠标循环点击器';
            app.UIFigure.Icon = fullfile(pathToMLAPP, 'mouse.png');
            app.UIFigure.Resize = 'off';

            % Create Image
            app.Image = uiimage(app.UIFigure);
            app.Image.ImageClickedFcn = createCallbackFcn(app, @ImageClicked, true);
            app.Image.Position = [538 501 85 65];
            app.Image.ImageSource = fullfile(pathToMLAPP, 'vsgif_com__.3078288.gif');

            % Create Panel_4
            app.Panel_4 = uipanel(app.UIFigure);
            app.Panel_4.TitlePosition = 'centertop';
            app.Panel_4.Title = '历史数据';
            app.Panel_4.BackgroundColor = [1 1 1];
            app.Panel_4.Position = [354 264 250 221];

            % Create ListBox
            app.ListBox = uilistbox(app.Panel_4);
            app.ListBox.Position = [19 75 212 110];

            % Create Button_4
            app.Button_4 = uibutton(app.Panel_4, 'state');
            app.Button_4.ValueChangedFcn = createCallbackFcn(app, @Button_4ValueChanged, true);
            app.Button_4.Text = '删除';
            app.Button_4.BackgroundColor = [1 1 1];
            app.Button_4.Position = [19 45 86 24];

            % Create Button_5
            app.Button_5 = uibutton(app.Panel_4, 'state');
            app.Button_5.ValueChangedFcn = createCallbackFcn(app, @Button_5ValueChanged, true);
            app.Button_5.Text = '恢复';
            app.Button_5.BackgroundColor = [1 1 1];
            app.Button_5.Position = [146 45 85 24];

            % Create EditField_8
            app.EditField_8 = uieditfield(app.Panel_4, 'text');
            app.EditField_8.Position = [19 11 106 22];

            % Create Button_6
            app.Button_6 = uibutton(app.Panel_4, 'push');
            app.Button_6.ButtonPushedFcn = createCallbackFcn(app, @Button_6Pushed, true);
            app.Button_6.BackgroundColor = [1 1 1];
            app.Button_6.Position = [146 10 85 24];
            app.Button_6.Text = '重命名';

            % Create Panel_3
            app.Panel_3 = uipanel(app.UIFigure);
            app.Panel_3.TitlePosition = 'centertop';
            app.Panel_3.Title = '坐标';
            app.Panel_3.BackgroundColor = [1 1 1];
            app.Panel_3.Position = [36 28 251 221];

            % Create UITable
            app.UITable = uitable(app.Panel_3);
            app.UITable.BackgroundColor = [1 1 1;0.9412 0.9412 0.9412];
            app.UITable.ColumnName = {'次序'; '横坐标'; '纵坐标'};
            app.UITable.RowName = {};
            app.UITable.ColumnEditable = [false true true];
            app.UITable.Position = [0 48 250 153];

            % Create Button_8
            app.Button_8 = uibutton(app.Panel_3, 'state');
            app.Button_8.ValueChangedFcn = createCallbackFcn(app, @Button_8ValueChanged, true);
            app.Button_8.Text = '删除';
            app.Button_8.BackgroundColor = [1 1 1];
            app.Button_8.Position = [171 11 73 24];

            % Create EditField_3
            app.EditField_3 = uieditfield(app.Panel_3, 'numeric');
            app.EditField_3.ValueChangedFcn = createCallbackFcn(app, @EditField_3ValueChanged, true);
            app.EditField_3.HorizontalAlignment = 'left';
            app.EditField_3.Position = [16 12 134 23];

            % Create Label_8
            app.Label_8 = uilabel(app.Panel_3);
            app.Label_8.FontColor = [0.651 0.651 0.651];
            app.Label_8.Position = [69 12 29 23];
            app.Label_8.Text = '次序';

            % Create Panel
            app.Panel = uipanel(app.UIFigure);
            app.Panel.TitlePosition = 'centertop';
            app.Panel.Title = '采点';
            app.Panel.BackgroundColor = [1 1 1];
            app.Panel.Position = [37 264 251 221];

            % Create Button
            app.Button = uibutton(app.Panel, 'state');
            app.Button.ValueChangedFcn = createCallbackFcn(app, @ButtonValueChanged, true);
            app.Button.Text = '开始';
            app.Button.BackgroundColor = [1 1 1];
            app.Button.Position = [41 11 167 23];

            % Create Label
            app.Label = uilabel(app.Panel);
            app.Label.HorizontalAlignment = 'right';
            app.Label.Position = [41 163 29 22];
            app.Label.Text = '数量';

            % Create EditField
            app.EditField = uieditfield(app.Panel, 'numeric');
            app.EditField.ValueChangedFcn = createCallbackFcn(app, @EditFieldValueChanged, true);
            app.EditField.HorizontalAlignment = 'center';
            app.EditField.Position = [85 163 123 22];
            app.EditField.Value = 1;

            % Create Label_2
            app.Label_2 = uilabel(app.Panel);
            app.Label_2.HorizontalAlignment = 'right';
            app.Label_2.Position = [41 112 29 22];
            app.Label_2.Text = '间隔';

            % Create EditField_2
            app.EditField_2 = uieditfield(app.Panel, 'numeric');
            app.EditField_2.ValueChangedFcn = createCallbackFcn(app, @EditField_2ValueChanged, true);
            app.EditField_2.HorizontalAlignment = 'center';
            app.EditField_2.Position = [85 112 123 22];
            app.EditField_2.Value = 3;

            % Create Label_5
            app.Label_5 = uilabel(app.Panel);
            app.Label_5.HorizontalAlignment = 'right';
            app.Label_5.Position = [41 62 29 22];
            app.Label_5.Text = '延时';

            % Create EditField_6
            app.EditField_6 = uieditfield(app.Panel, 'numeric');
            app.EditField_6.ValueChangedFcn = createCallbackFcn(app, @EditField_6ValueChanged, true);
            app.EditField_6.HorizontalAlignment = 'center';
            app.EditField_6.Position = [85 62 123 22];
            app.EditField_6.Value = 2;

            % Create Panel_2
            app.Panel_2 = uipanel(app.UIFigure);
            app.Panel_2.TitlePosition = 'centertop';
            app.Panel_2.Title = '循环点击';
            app.Panel_2.BackgroundColor = [1 1 1];
            app.Panel_2.Position = [354 28 250 220];

            % Create Button_3
            app.Button_3 = uibutton(app.Panel_2, 'state');
            app.Button_3.ValueChangedFcn = createCallbackFcn(app, @Button_3ValueChanged, true);
            app.Button_3.Text = '开始';
            app.Button_3.BackgroundColor = [1 1 1];
            app.Button_3.Position = [39 10 174 23];

            % Create EditField_4Label
            app.EditField_4Label = uilabel(app.Panel_2);
            app.EditField_4Label.HorizontalAlignment = 'right';
            app.EditField_4Label.Position = [38 122 29 22];
            app.EditField_4Label.Text = '间隔';

            % Create EditField_4
            app.EditField_4 = uieditfield(app.Panel_2, 'numeric');
            app.EditField_4.ValueChangedFcn = createCallbackFcn(app, @EditField_4ValueChanged, true);
            app.EditField_4.HorizontalAlignment = 'center';
            app.EditField_4.Position = [82 122 130 22];
            app.EditField_4.Value = 0.01;

            % Create Label_3
            app.Label_3 = uilabel(app.Panel_2);
            app.Label_3.HorizontalAlignment = 'right';
            app.Label_3.Position = [38 160 29 22];
            app.Label_3.Text = '次数';

            % Create EditField_5
            app.EditField_5 = uieditfield(app.Panel_2, 'numeric');
            app.EditField_5.ValueChangedFcn = createCallbackFcn(app, @EditField_5ValueChanged, true);
            app.EditField_5.HorizontalAlignment = 'center';
            app.EditField_5.Position = [82 160 130 22];
            app.EditField_5.Value = 10;

            % Create Label_6
            app.Label_6 = uilabel(app.Panel_2);
            app.Label_6.HorizontalAlignment = 'right';
            app.Label_6.Position = [38 85 29 22];
            app.Label_6.Text = '延时';

            % Create EditField_7
            app.EditField_7 = uieditfield(app.Panel_2, 'numeric');
            app.EditField_7.ValueChangedFcn = createCallbackFcn(app, @EditField_7ValueChanged, true);
            app.EditField_7.HorizontalAlignment = 'center';
            app.EditField_7.Position = [82 85 130 22];
            app.EditField_7.Value = 1;

            % Create CheckBox
            app.CheckBox = uicheckbox(app.Panel_2);
            app.CheckBox.Text = '随机扰动';
            app.CheckBox.Position = [40 48 70 22];

            % Create CheckBox_2
            app.CheckBox_2 = uicheckbox(app.Panel_2);
            app.CheckBox_2.Text = '存在漂移';
            app.CheckBox_2.Position = [139 48 70 22];

            % Create Label_4
            app.Label_4 = uilabel(app.UIFigure);
            app.Label_4.FontSize = 28;
            app.Label_4.Position = [220 514 202 37];
            app.Label_4.Text = '鼠标循环点击器';

            % Create Lamp
            app.Lamp = uilamp(app.UIFigure);
            app.Lamp.Position = [307 247 28 28];
            app.Lamp.Color = [1 1 1];

            % Create Hyperlink
            app.Hyperlink = uihyperlink(app.UIFigure);
            app.Hyperlink.URL = 'https://blog.csdn.net/fair_li/article/details/128348791?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22128348791%22%2C%22source%22%3A%22fair_li%22%7D';
            app.Hyperlink.Position = [38 495 31 22];
            app.Hyperlink.Text = 'Help';

            % Create Label_10
            app.Label_10 = uilabel(app.UIFigure);
            app.Label_10.HorizontalAlignment = 'center';
            app.Label_10.Position = [438 544 134 22];
            app.Label_10.Text = '';

            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = auto_mouse

            % Create UIFigure and components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.UIFigure)

            % Execute the startup function
            runStartupFcn(app, @startupFcn)

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end