CALISVALIS1010
CALISVALIS1010

Reputation: 323

Error when running a simple pynput program

I'm making a project and a part of it is making a program that when activated, automatically right clicks whenever I left click. But when I launch the program and left click, it returns an error: TypeError: combatModules.on_click() takes 4 positional arguments but 5 were given My code: (I'm using threads so i can have multiple programs running at once from the same program.)

import pydirectinput as pa
import time as t
import pynput
import threading
class combatModules:
    def __init__(self) -> None:
        pass
    
    def on_click(x, y, button, pressed):
        if button == pynput.mouse.Button.left:
            print('{} at {}'.format('Pressed Left Click' if pressed else 'Released Left Click', (x, y)))
            pa.rightClick()
        else:
            print('{} at {}'.format('Pressed Right Click' if pressed else 'Released Right Click', (x, y)))
        
    def blockHitCode(self):
        for i in range(100):
            listener = pynput.mouse.Listener(on_click=self.on_click)
            listener.start()
            listener.join()
    def blockHit(self):
        blockHitThread = threading.Thread(target=self.blockHitCode)
        blockHitThread.start()

A little explanation: blockHit() is meant to be executed from the main program.

Upvotes: 0

Views: 75

Answers (1)

DNy
DNy

Reputation: 799

Your method is missing the self argument. This is required for methods in a class like you have with the blockHitCode and blockHit.

This should fix the error you are having:

def on_click(self, x, y, button, pressed):

Upvotes: 1

Related Questions