Skip to content

Commit

Permalink
Switch to pyautogui (#35)
Browse files Browse the repository at this point in the history
* Prevent the '1' file from being created and install pyautogui

* Try pynput instead (seems to be more stable)

* Add item to the todo list for this branch

* Simplyfy ms code

* Reduce duped code

* Remove that stupid keyboard lib

* Update requirements

* Root is not needed anymore

* Not sure what is best to use

* Works on windows

* Undo that

* Errors are no longer logged

* Remove readme junk

* Use pyautogui for the numpad

* add test for Mk3

* Fixed conda env and version number

* Update environment-build.yml

* Fixed pyinstaller issues

* Move requirements.txt to INSTALL

* Test diff kb lib for windows

* Nope

* Prepare windows keyboard api

* Add untested code for pressing keys

* Add a lot of keycodes

* Add numpad to unix

* Implement keys that LPHK uses

* Use pyautogui for writing strings

* Add LPX support (#42)

Launchpad X support and small changes

* Made to use launchpad.py master branch

* Add a few missing keys

Co-authored-by: nimaid <[email protected]>
Co-authored-by: Malik Enes Şafak <[email protected]>
  • Loading branch information
3 people authored May 8, 2020
1 parent 3d5b4bb commit 562fe7f
Show file tree
Hide file tree
Showing 20 changed files with 1,271 additions and 844 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ __pycache__/
# C extensions
*.so

# intellij/PyCharm
.idea/

# Distribution / packaging
.Python
build/
Expand Down
7 changes: 4 additions & 3 deletions INSTALL/environment-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ dependencies:
- pip
- tk
- pip:
- keyboard
- launchpad-py
- git+git://github.com/FMMT666/launchpad.py.git@master
- pillow
- pygame
- pynput
- tkcolorpicker
- pyinstaller
- https://github.com/pyinstaller/pyinstaller/archive/develop.zip
- py-getch
- pyautogui
5 changes: 3 additions & 2 deletions INSTALL/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ dependencies:
- pip
- tk
- pip:
- keyboard
- launchpad-py
- git+git://github.com/FMMT666/launchpad.py.git@master
- pillow
- pygame
- pynput
- tkcolorpicker
- py-getch
- pyautogui
6 changes: 3 additions & 3 deletions INSTALL/linux_beta/install_linux.bash
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function uninstall_LPHK () {


# If conda isn't found, prompt to install it as well
conda > /dev/null 2>1 && CONDAGOOD=1 || CONDAGOOD=0
conda > /dev/null 2>&1 && CONDAGOOD=1 || CONDAGOOD=0
if [ $CONDAGOOD = 0 ]; then
echo "No conda found. Install Miniconda3 and LPHK?"
prompt_yn
Expand All @@ -103,7 +103,7 @@ if [ $CONDAGOOD = 0 ]; then
fi

# If LPHK is already installed, offer to uninstall
LPHKENVDIR=$(cat ~/.conda/environments.txt | grep LPHK) > /dev/null 2>1
LPHKENVDIR=$(cat ~/.conda/environments.txt | grep LPHK) > /dev/null 2>&1
if [ ! -z $LPHKENVDIR ]; then
echo "LPHK already installed! Uninstall LPHK?"
prompt_yn
Expand Down Expand Up @@ -147,7 +147,7 @@ else
echo "Installing LPHK..."
install_LPHK
# Get the new location after install
LPHKENVDIR=$(cat ~/.conda/environments.txt | grep LPHK) > /dev/null 2>1
LPHKENVDIR=$(cat ~/.conda/environments.txt | grep LPHK) > /dev/null 2>&1
echo "LPHK environment set up. Run '[your lphk directory]/run.bash'"
else
echo "Not installing LPHK, exiting..."
Expand Down
17 changes: 17 additions & 0 deletions INSTALL/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
MouseInfo==0.1.3
Pillow==7.1.1
py-getch==1.0.1
PyAutoGUI==0.9.50
pygame==1.9.6
PyGetWindow==0.0.8
PyMsgBox==1.0.7
pynput==1.6.8
pyperclip==1.8.0
PyRect==0.1.4
PyScreeze==0.1.26
python-xlib==0.27
python3-xlib==0.15
PyTweening==1.0.3
six==1.14.0
tkcolorpicker==2.1.3
-e git+git://github.com/FMMT666/launchpad.py.git@3e3fc3b2589d9ced80bc6c9b218dd90c8a2dd485#egg=launchpad-py
13 changes: 10 additions & 3 deletions LPHK.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ def get_first_textfile_line(file_path):
import logger
logger.start(LOG_PATH)


# Start printing output
def datetime_str():
now = datetime.now()
return now.strftime("%d/%m/%Y %H:%M:%S")
now = datetime.now()
return now.strftime("%d/%m/%Y %H:%M:%S")


print("---------------- BEGIN LOG", datetime_str(), "----------------")
print("LPHK - LaunchPad HotKey - A Novation Launchpad Macro Scripting System")
Expand All @@ -83,10 +85,13 @@ def datetime_str():
print("")

import lp_events, scripts, kb, files, sound, window
from utils import launchpad_connector

lp = launchpad.Launchpad()

EXIT_ON_WINDOW_CLOSE = True


def init():
global EXIT_ON_WINDOW_CLOSE
if len(sys.argv) > 1:
Expand All @@ -112,7 +117,7 @@ def shutdown():
if window.lp_connected:
scripts.unbind_all()
lp_events.timer.cancel()
lp.Close()
launchpad_connector.disconnect(lp)
window.lp_connected = False
logger.stop()
if window.restart:
Expand All @@ -122,10 +127,12 @@ def shutdown():
os.execv(sys.executable, ["\"" + sys.executable + "\""] + sys.argv)
sys.exit("[LPHK] Shutting down...")


def main():
init()
window.init(lp, launchpad, PATH, PROG_PATH, USER_PATH, VERSION, PLATFORM)
if EXIT_ON_WINDOW_CLOSE:
shutdown()


main()
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ I have specifically chosen to do my best to develop this using as many cross pla

## Installation [[Table of Contents]](https://github.com/nimaid/LPHK#table-of-contents)
*Note: Files used in the installation are named with a version number, and will change with each new release. The word `VERSION` is used in the below filenames and paths to denote where this version number will be. When going to [https://github.com/nimaid/LPHK/releases/latest](https://github.com/nimaid/LPHK/releases/latest), it will redirect to the page with the latest versions of these files, so the correct value of `VERSION` should be plainly obvious.*
*Note: Because pyautogui is used you may need to install some extra libraries to your machine, more info on this page: [https://pyautogui.readthedocs.io/en/latest/install.html](https://pyautogui.readthedocs.io/en/latest/install.html)*

### Windows Install/Run Instructions [[Table of Contents]](https://github.com/nimaid/LPHK#table-of-contents)
*Is these pre-built binaries do not work for you, please share the issue in the Discord or as a GitHub issue. In the meantime, advanced users can use `INSTALL\environment.yml` to install the LPHK conda environment, and then run `python LPHK.py` after activating it.*
Expand Down Expand Up @@ -503,4 +504,4 @@ In order of priority:
* ~~Make a special color picker for Classic/Mini/S that only has the 16 possible colors~~
* ~~Re-write `files.py` to use a JSON format for layouts.~~
* ~~Make an installer for Windows~~
* ~~Simply strip comments and empty lines before the first real command. That way, first line can be a comment and second a header, etc.~~
* ~~Simply strip comments and empty lines before the first real command. That way, first line can be a comment and second a header, etc.~~
2 changes: 0 additions & 2 deletions RUN.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/bin/bash -i
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# https://ubuntuforums.org/showthread.php?t=2290602
xhost +
python $DIR/LPHK.py
conda deactivate
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.10
0.3.0_pr35_07042020
27 changes: 16 additions & 11 deletions kb.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
import keyboard
import ms
import sys

media_keys = {"vol_up" : 57392, "vol_down" : 57390, "mute" : 57376, "play_pause" : 57378, "prev_track" : 57360, "next_track" : 57369, "mouse_left" : "mouse_left","mouse_middle" : "mouse_middle", "mouse_right" : "mouse_right"}
if sys.platform == 'win32':
import system_apis.keyboard_win as keyboard_api
else:
import system_apis.keyboard_unix as keyboard_api

pressed = set()


def sp(name):
try:
return keyboard.key_to_scan_codes(str(name))[0]
except ValueError:
try:
return media_keys[str(name)]
except KeyError:
return None
return keyboard_api.sp(name)


def press(key):
pressed.add(key)
if type(key) == str:
if "mouse_" in key:
ms.press(key[6:])
return
keyboard.press(key)
keyboard_api.press(key)


def release(key):
pressed.discard(key)
if type(key) == str:
if "mouse_" in key:
ms.release(key[6:])
return
keyboard.release(key)
keyboard_api.release(key)


def release_all():
for key in pressed.copy():
release(key)


def tap(key):
if type(key) == str:
if "mouse_" in key:
Expand All @@ -42,3 +44,6 @@ def tap(key):
press(key)
release(key)


def write(string):
keyboard_api.write(string)
2 changes: 1 addition & 1 deletion lp_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ def raw_clear():
for x in range(9):
for y in range(9):
if window.lp_mode == "Mk1":
lp_object.LedCtrlXY(x, y, 0, 0)
lp_object.LedCtrlXY(x, y, 0, 0)
else:
lp_object.LedCtrlXYByCode(x, y, 0)
44 changes: 23 additions & 21 deletions ms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,46 @@
from bresenham import bresenham

controller = Controller()
buttons = ["left", "middle", "right"]

def getXY():

def get_pos():
return controller.position

def setXY(x, y):

def set_pos(x, y):
global controller
controller.position = (x, y)

def moveXY(x, y):

def move_to_pos(x, y):
controller.move(x, y)


def click(button="left", clicks=1):
if button == "left":
controller.click(Button.left, clicks)
elif button == "middle":
controller.click(Button.middle, clicks)
elif button == "right":
controller.click(Button.right, clicks)
_check_button(button)
controller.click(Button[button], clicks)


def press(button="left"):
if button == "left":
controller.press(Button.left)
elif button == "middle":
controller.press(Button.middle)
elif button == "right":
controller.press(Button.right)
_check_button(button)
controller.press(Button[button])


def release(button="left"):
if button == "left":
controller.release(Button.left)
elif button == "middle":
controller.release(Button.middle)
elif button == "right":
controller.release(Button.right)
_check_button(button)
controller.release(Button[button])


def scroll(x, y):
controller.scroll(x, y)


def line_coords(x1, y1, x2, y2):
return list(bresenham(x1, y1, x2, y2))


def _check_button(btn):
if btn not in buttons:
raise ValueError('The mouse button specified is not valid')

Loading

0 comments on commit 562fe7f

Please sign in to comment.