Skip to content

Instantly share code, notes, and snippets.

@actuallyjamez
Created January 20, 2019 00:15
Show Gist options
  • Select an option

  • Save actuallyjamez/d7b947b55968138d241745290461a6e8 to your computer and use it in GitHub Desktop.

Select an option

Save actuallyjamez/d7b947b55968138d241745290461a6e8 to your computer and use it in GitHub Desktop.
Ableton live middle click to pan script
from pynput import mouse
from pynput.keyboard import Key
from pynput.keyboard import Controller as KeyControl
from pynput.mouse import Button
from pynput.mouse import Controller as MouseControl
keyboard = KeyControl()
mouse_control = MouseControl()
currently_pressed = False
def on_click(x, y, button, pressed):
global currently_pressed
if button == mouse.Button.middle and pressed and not currently_pressed:
keyboard.press(Key.ctrl_l)
keyboard.press(Key.alt_l)
mouse_control.press(Button.left)
currently_pressed = True
if button == mouse.Button.middle and not pressed and currently_pressed:
keyboard.release(Key.ctrl_l)
keyboard.release(Key.alt_l)
mouse_control.release(Button.left)
currently_pressed = False
# Collect events until released
with mouse.Listener(
on_click=on_click,
) as listener:
listener.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment