Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
r0levrai authored Mar 27, 2020
1 parent 9699841 commit 839f351
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions macro_one_step_from_eden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python


# imports
try:
from pynput import mouse, keyboard
except ModuleNotFoundError:
print("Your python does not have pynput installed. Let us change that...")
import os
os.system("pip install pynput")
print("...done.")
from pynput import mouse, keyboard


# listeners
def on_click(x, y, button, pressed):
if pressed:
if button == mouse.Button.left:
keyboard_controller.press(keyboard.Key.left)
keyboard_controller.release(keyboard.Key.left)
print("Left")
if button == mouse.Button.right:
keyboard_controller.press(keyboard.Key.right)
keyboard_controller.release(keyboard.Key.right)
print("Right")

def on_scroll(x, y, dx, dy):
if dy > 0: # up
keyboard_controller.press(keyboard.Key.up)
print("Uuu...")
else: # down
keyboard_controller.release(keyboard.Key.up)
print("...up")


# main
keyboard_controller = keyboard.Controller()
with mouse.Listener(
on_click=on_click,
on_scroll=on_scroll) as mouse_listener:
print("Macro launched. Happy One Step From Eden run :)")
# wait until mouse_listener.stop called or StopException raised or on_* returns False
mouse_listener.join()
# clean keys that are still down
keyboard.release(keyboard.Key.up)

0 comments on commit 839f351

Please sign in to comment.