I have a program that is working, but it opens the context menu after simulating the commands. (That's because it's done with the right mouse button).
Is there a way to not open the context menu if a mouse gesture is executed?
Is there a way to not open the context menu if a mouse gesture is executed?
from pynput.mouse import Listener, Button
from pynput.keyboard import Key, Controller
import time
is_right_button_pressed = False
initial_x = 0
initial_y = 0
min_movement = 20
max_x_deviation = 10
max_y_deviation = 10
keyboard = Controller()
right_button_pressed_time = 0
def on_click(x, y, button, pressed):
global is_right_button_pressed, initial_x, initial_y, right_button_pressed_time
if button == Button.right:
if pressed:
is_right_button_pressed = True
initial_x = x
initial_y = y
right_button_pressed_time = time.time()
else:
if is_right_button_pressed:
is_right_button_pressed = False
elapsed_time = time.time() - right_button_pressed_time
if elapsed_time <= 2:
x_diff = initial_x - x
y_diff = initial_y - y
if abs(y_diff) <= max_y_deviation:
if x_diff > min_movement:
keyboard.press(Key.alt)
keyboard.press(Key.left)
keyboard.release(Key.left)
keyboard.release(Key.alt)
elif x_diff < -min_movement:
keyboard.press(Key.alt)
keyboard.press(Key.right)
keyboard.release(Key.right)
keyboard.release(Key.alt)
if abs(x_diff) <= max_x_deviation:
if y_diff > min_movement:
keyboard.press(Key.home)
keyboard.release(Key.home)
elif y_diff < -min_movement:
keyboard.press(Key.end)
keyboard.release(Key.end)
if y_diff < -min_movement and x_diff > min_movement:
keyboard.press(Key.win)
keyboard.press('d')
keyboard.release('d')
keyboard.release(Key.win)
def on_press(key):
if key == Key.menu:
return False
with Listener(on_click=on_click) as listener:
with Listener(on_press=on_press) as context_listener:
listener.join()
context_listener.join()I want that the context menu does not appear if a mouse gesture action is performed.
Larz60+ write Aug-21-2023, 02:49 AM:
Added the tags for you this time. Please use bbcode tags on future posts. See link in deanhystad's moderation note below
Added the tags for you this time. Please use bbcode tags on future posts. See link in deanhystad's moderation note below
deanhystad write Aug-20-2023, 07:16 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
