Skip to content

Instantly share code, notes, and snippets.

@Lampe2020
Last active March 19, 2023 21:58
Show Gist options
  • Save Lampe2020/ad058d6d88f110d25bf62a37de616680 to your computer and use it in GitHub Desktop.
Save Lampe2020/ad058d6d88f110d25bf62a37de616680 to your computer and use it in GitHub Desktop.

Revisions

  1. Lampe2020 revised this gist Mar 19, 2023. 2 changed files with 16 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions autoclicker_offline.desktop
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    #!/usr/bin/env xdg-open
    [Desktop Entry]
    Encoding=UTF-8
    Version=1.0
    Name=Autoclicker
    Type=Application
    Icon=python3
    Exec=python3 autoclicker.py # Requires local copy of the script but no internet connection.
    8 changes: 8 additions & 0 deletions autoclicker_online.desktop
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    #!/usr/bin/env xdg-open
    [Desktop Entry]
    Encoding=UTF-8
    Version=1.0
    Name=Autoclicker
    Type=Application
    Icon=python3
    Exec=bash -c "curl -H 'Cache-Control: no-cache, no-store' https://gist.github.com/Stehlampe2020/ad058d6d88f110d25bf62a37de616680/raw/autoclicker.py | python3"
  2. Lampe2020 revised this gist Mar 19, 2023. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions autoclicker.py
    Original file line number Diff line number Diff line change
    @@ -20,17 +20,17 @@ def __init__(self):

    # Create a multiple-choice box
    button_menu = Gtk.ComboBoxText()
    button_menu.insert(0, "1", "Vänster")
    button_menu.insert(1, "2", "Mitten")
    button_menu.insert(2, "3", "Höger")
    button_menu.insert(0, "1", "Left click")
    button_menu.insert(1, "2", "Middle click")
    button_menu.insert(2, "3", "Right click")
    button_menu.set_active(0)

    # Create a number selection box
    interval_spinner = Gtk.SpinButton.new_with_range(0, 3333, 1)
    interval_spinner.set_value(1)

    # Create a button
    start_button = Gtk.Button(label="Starta/Stoppa")
    start_button = Gtk.Button(label="Start/Stop")
    start_button.connect("clicked", self.init_autoclicker, button_menu, interval_spinner)

    # Attach widgets to grid
  3. Lampe2020 revised this gist Mar 19, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions autoclicker.py
    Original file line number Diff line number Diff line change
    @@ -60,9 +60,9 @@ def click(self):
    ...

    def init_autoclicker(self, button, button_menu, interval_spinner):
    button_value = int(button_menu.get_active_id())
    interval_value = interval_spinner.get_value_as_int()
    if not self.currently_running_process:
    self.button = int(button_menu.get_active_id())
    self.interval = interval_spinner.get_value_as_int()
    self.currently_running_process = multiprocessing.Process(target=self.click)
    self.currently_running_process.start()
    else:
  4. Lampe2020 revised this gist Mar 19, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion autoclicker.py
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@

    class MainWindow(Gtk.Window):
    def __init__(self):
    Gtk.Window.__init__(self, title="Autoklicker")
    Gtk.Window.__init__(self, title="Autoclicker")
    self.set_border_width(10)
    self.currently_running_process = None
    self.button = 1
  5. Lampe2020 created this gist Mar 19, 2023.
    76 changes: 76 additions & 0 deletions autoclicker.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,76 @@
    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-

    import gi, time, os, random, multiprocessing
    gi.require_version("Gtk", "3.0")
    from gi.repository import Gtk

    class MainWindow(Gtk.Window):
    def __init__(self):
    Gtk.Window.__init__(self, title="Autoklicker")
    self.set_border_width(10)
    self.currently_running_process = None
    self.button = 1
    self.interval = 1
    self.method = 'click'

    # Create a grid
    grid = Gtk.Grid()
    self.add(grid)

    # Create a multiple-choice box
    button_menu = Gtk.ComboBoxText()
    button_menu.insert(0, "1", "Vänster")
    button_menu.insert(1, "2", "Mitten")
    button_menu.insert(2, "3", "Höger")
    button_menu.set_active(0)

    # Create a number selection box
    interval_spinner = Gtk.SpinButton.new_with_range(0, 3333, 1)
    interval_spinner.set_value(1)

    # Create a button
    start_button = Gtk.Button(label="Starta/Stoppa")
    start_button.connect("clicked", self.init_autoclicker, button_menu, interval_spinner)

    # Attach widgets to grid
    grid.attach(button_menu, 0, 0, 1, 1)
    grid.attach(interval_spinner, 1, 0, 1, 1)
    grid.attach(start_button, 0, 1, 2, 1)

    # Close the clicker process on window close
    self.connect('destroy', Gtk.main_quit)
    self.connect('delete-event', (lambda self, widget=None, *data: self.currently_running_process.terminate()))

    def click(self):
    if not self.button in (1, 2, 3) or not type(self.interval) == int:
    return {'button': self.button, 'interval': self.interval}
    match self.method:
    case 'mousedown':
    while True:
    time.sleep(self.interval + random.random()) # Use additional random delay to avoid detection
    os.system(f'xdotool mousedown {self.button}')
    time.sleep(random.random() / 10)
    os.system(f'xdotool mouseup {self.button}')
    case 'click':
    while True:
    time.sleep(self.interval + random.random()) # Use additional random delay to avoid detection
    os.system(f'xdotool click {self.button}')
    case _:
    ...

    def init_autoclicker(self, button, button_menu, interval_spinner):
    button_value = int(button_menu.get_active_id())
    interval_value = interval_spinner.get_value_as_int()
    if not self.currently_running_process:
    self.currently_running_process = multiprocessing.Process(target=self.click)
    self.currently_running_process.start()
    else:
    self.currently_running_process.terminate()
    self.currently_running_process.join()
    self.currently_running_process = None

    win = MainWindow()
    win.connect("destroy", Gtk.main_quit)
    win.show_all()
    Gtk.main()