Using Perl, Python, or Ruby, how to write a program to “click” on the screen at scheduled time?

前端 未结 5 1558
眼角桃花
眼角桃花 2021-01-16 02:32

Using Perl, Python, or Ruby, can I write a program, probably calling Win32 API, to \"click\" on the screen at scheduled time, like every 1 hour?

Details:

相关标签:
5条回答
  • 2021-01-16 02:57

    If using a different tool is allowed, you should take a look at AutoHotkey or AutoIt. These tools were made for this sort of thing, and I've always been keen on using the right tools for the right jobs.

    AutoHotkey is based on AutoIt I believe, and it is my personal preference. You only really need 2 functions for what you're trying to achieve, MouseMove and MouseClick.

    0 讨论(0)
  • 2021-01-16 03:06

    If you are trying to automate some task in a website you might want to look at WWW::Selenium. It, along with Selenium Remote Control, allows you to remote control a web browser.

    0 讨论(0)
  • 2021-01-16 03:08

    To answer the actual question, in Perl, you would use the SendMouse (and the associated functions) provided by the Win32::GuiTest module.

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use Win32::GuiTest qw( MouseMoveAbsPix SendMouse );
    
    MouseMoveAbsPix(640,400);
    SendMouse "{LEFTCLICK}";
    
    __END__
    

    UPDATE:

    What if some virus scanning program pops up covering up the place where the click should happen?

    In that case, you would use FindWindowLike to find the window and MouseClick to send a click to that specific window.

    0 讨论(0)
  • 2021-01-16 03:12

    In Python there is ctypes and in Perl there is Win32::API

    ctypes Example

    from ctypes import *
    windll.user32.MessageBoxA(None, "Hey MessageBox", "ctypes", 0);
    

    Win32::Api Example

    use Win32::GUI qw( WM_CLOSE );
    my $tray = Win32::GUI::FindWindow("WindowISearchFor","WindowISearchFor");
    Win32::GUI::SendMessage($tray,WM_CLOSE,0,0);
    
    0 讨论(0)
  • 2021-01-16 03:13

    I find this is easier to approach in Java or C++. Java has a Robot class that allows you to just pass x, y coordinates and click somewhere. Using C++, you can achieve that same functionality using mouse_event() or SendMessage() with the WM_MOUSE_DOWN flag. SendMessage is more technical but it allows you to use FindWindow() and send mouse clicks to a specific window, even if it's minimized.

    Using a scripting language like Python or Ruby, I'd guess that you'd end up hooking into one of these Windows API functions anyway.

    0 讨论(0)
提交回复
热议问题