1

I want to create a tool, which allows me to send keys to active window using my mouse.

Let's say I want to send the key "A" when I click the left mouse button. But I also want to suppress / dispose that particular click event. So the target app will only feel the keyboard input "A", but not the left click of the mouse event.

With the following code I am able to see the mouse clicks. But I want to dispose / stop the event and not processed by the system.

from pynput import mouse

def do_something():
    print("something")

def on_click(x, y, button, pressed):
    print('{0} {1} at {2}'.format(button, 'Pressed' if pressed else 'Released', (x, y)))
    if (button.value == 1):
        do_something()
        #suppress / dispose the click event...

# Collect events until released
with mouse.Listener( on_click=on_click ) as listener:
    listener.join()

By the way I am using Ubuntu 20.04. Thanks in advance.

1 Answer 1

1

I found a way that suppress all the click events.

from pynput import mouse

def do_something():
    print("something")

def on_click(x, y, button, pressed):
    print('{0} {1} at {2}'.format(button, 'Pressed' if pressed else 'Released', (x, y)))
    if (button.value == 1):
        do_something()
        #suppress / dispose the click event...

# Collect events until released
with mouse.Listener( on_click=on_click, suppress=True ) as listener:
    listener.join()

I am still looking for a solution to suppress a certain button click.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.