Code Monkey home page Code Monkey logo

lphk's Introduction

LPHK (LaunchPad HotKey)

A Novation Launchpad macro scripting system.

Update 4

Table of Contents

LPHK HomepageLPHK HomepageLPHK HomepageLPHK HomepageLPHK Discord ChatLPHK Discord ChatLPHK Discord ChatLPHK PatreonLPHK PatreonLPHK PatreonLPHK Patreon

What does it do? [Table of Contents]

The goal of this project is to implement a macro scripting system for the Novation Launchpad, in order to use the launchpad as a scriptable, general purpose macro keyboard.

It uses "LPHKscript", a very simple scripting language similar to DuckyScript, and has a GUI to enter scripts, set colors, and to save/load your setup.

LPHK can be used for the following:

  • Gaming, to bind:
    • Items
    • Volume
    • Attacks
    • Typed commands
    • Automatic Glitch/Trick Execution (think ABH or propsurfing in Source)
    • Repetitive tasks (grinding)
    • Reference Website launcher
    • Window switcher
  • Streaming, to bind:
    • Sound effects
    • Streaming software hotkeys
    • Quickly open a folder with assets
  • Editing, to bind:
    • Cuts/insertions
    • Modes
    • Effects
    • Render
    • Preview
    • Scrubbing
    • Automate repetitive tasks
  • Programming, to bind:
    • Repetitive re-formatting
    • Commenting code
    • Auto-typing function/loop templates
    • Compiling/executing
    • Breakpoints
    • Debugger
  • As an interface to other programs with hotkeys
  • ... and many more!

LPHK has all of its core features functional and ready to use! There are a lot of new features wanted, and there are massive bugs that need fixing, and it needs some more polish, but you can still do quite a lot with it as it is currently!

LPHK is still a work-in-progress, so things will be changing often. See below for a todo list. I have a life (a crazy one at that), so no promises on a delivery date. Feel free to offer your help! You can see project updates and ask questions on the official Discord server! You can also donate on the official Patreon page to help speed up development, or just say thanks!

Compatibility [Table of Contents]

I have specifically chosen to do my best to develop this using as many cross platform libraries as possible, with a hard requirement that Linux and Windows be supported, and a strong preference for Mac as well. The GUI is driven by TK, which works on all of the above plus Unix. The interface with the launchpad and several script functions are built on pygame, which is compatible with basically everything ever. Pretty much everything else is standard Python 3.

Current compatibility:

  • Windows
    • Strong compatibility
      • Everything works
      • This is the platform it is developed on
    • Includes pre-built binaries with nothing else required (PyInstaller)
      • Graphical installer (Inno Setup)
      • Portable version (Single .exe)
  • Linux
    • Weak compatibility
      • Many bugs, mostly with system permissions
      • Most systems are unable to run it at all
      • Please try to install and report your issues on the Discord or as a Github issue.
        • Include LPHK.log
    • Pre-built binaries building, but not released
      • If anybody installs on Linux successfully and lets me know, I will start releasing binaries.
  • Mac
    • Completely untested

Installation [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, 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

Windows Install/Run Instructions [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.

  • If you want the installed version (recommended)
    • Download the latest LPHK_setup_VERSION.exe file from https://github.com/nimaid/LPHK/releases/latest
    • Run LPHK_setup_VERSION.exe` and follow the on-screen setup instructions.
    • To run LPHK, use one of the shortcuts, either the Start Menu or Desktop one (if you selected that option).
    • You can uninstall LPHK like any other program, with the Windows Add or remove programs utility.
      • There will also be an uninstaller named unins000.exe in the program folder. You can open the program folder by clicking the menu option Help > Program folder....
    • LPHK also creates a folder in My Documents named LPHK. This is where layouts, scripts, sounds, and the log is stored. You can open this folder by clicking the menu option Help > User folder....
  • If you want to run LPHK portably (advanced)
    • This method lets you use LPHK by simply downloading LPHK_portable_win_VERSION.zip and extracting it to a folder of your choice. You can then move the folder to a flash drive, between computers, etc.
    • It takes much longer to start up this way
    • Run LPHK.exe

Linux Install/Run Instructions [Table of Contents]

The following instructions are for a beta version installer that aims to be fairly easyto use. Eventually, once Linux stability improves, there will be pre-built binaries released. Until then, if this installer fails, 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.

THE FOLLOWING INSTRUCTIONS ARE FOR THE BETA INSTALLER, WHICH AIMS TO BE PAINLESS TO USE. IT IS GOING TO SOON BE REPLACED BY BINARY RELEASES. IF THIS INSTALLER FAILS, TRY MANUALLY INSTALLING CONDA AND THE CONDA ENVIRONMENT IN INSTALL/environment.yml. THEN, RUN LPHK.py INSIDE THE LPHK CONDA ENVIRONMENT.

  • Download the source of the latest release at https://github.com/nimaid/LPHK/releases/latest
    • Either the VERSION.zip or VERSION.tar.gz file will work, but the VERSION.zip file is probably easier to use
  • Extract the LPHK-VERSION folder
  • Run LPHK-VERSION/INSTALL/linux_beta/install_linux.bash" via a bash shell (NOT sh, fish, etc.)
    • You can do this via terminal or, if it's set up, by double clicking it.
  • One of three things will happen:
    • If LPHK is already installed, it will prompt if you would like to uninstall it. Type either y or n and press enter.
      • At the moment, this only uninstalls the conda environment. You still have to manually delete the LPHK files and shortcuts.
      • If Miniconda3 is installed in ~/miniconda3/, it will prompt if you would like to uninstall that as well. Type either y or n and press enter.
    • If you do not have a conda distribution installed, it will prompt you if you want to install Miniconda3 and LPHK. Type y and press enter.
    • If a conda distribution is already installed, the installer will prompt you if you want to install LPHK. Type y and press enter.
  • To run LPHK, run LPHK-VERSION/RUN.bash.
    • .desktop shortcuts are coming soon!

How do I use it? (Post-Install) [Table of Contents]

  • Before starting the program, make sure your Launchpad Classic/Mini/S or MkII is connected to the computer.
    • If you have a Launchpad Pro, there is currently beta support for it. Please put it in Live mode by following the instructions in the pop-up when trying to connect in the next step. For more info, see the User Manual.
  • Click Launchpad > Connect to Launchpad....
    • If the connection is successful, the grid will appear, and the status bar at the bottom will turn green.
  • The current mode is displayed in the upper right, in the gap between the circular buttons. Clicking this text will change the mode. There are four modes:
    • "Edit" mode: Click on a button to open the Script Edit window for that button.
      • All scripts are saved in the .lpl (LaunchPad Layout) files, but the editor also has the ability to import/export single .lps (LaunchPad Script) files.
        • For examples, you can click Import Script and look through the user_scripts/examples/ folder.
      • Select the button color, then click Bind Button (x, y).
        • If there are syntax errors, this is when they will be caught, and you will be informed without the editor closing.
    • "Move" mode: Click on a button to highlight it, then click on a second button to move the script/color from the highlighted one.
      • The selected button will be unbound
      • The second button will have the selected button's old script and color bound to it
        • If the second button is already bound, you will get a dialog box with options.
    • "Swap" mode: Click on a button to highlight it, then click on a second button to swap the script/color with the highlighted one.
      • The selected button will have the second button's script and color bound to it.
      • The second button will have the selected button's old script and color bound to it.
    • "Copy" mode: Click on a button to highlight it, then click on a second button to copy the script/color to the highlighted one.
      • The selected button will remain unchanged.
      • The second button will have the selected button's old script and color bound to it.
        • If the second button is already bound, you will get a dialog box with options.
  • Go to Layout > Save layout as... to save your current layout for future use, colors and all.
  • Go to Layout > Load layout... to load an existing layout. Examples are in user_layouts/examples/.
  • (Optional) Create a layout with the name startup.lpl that will be automatically loaded every time LPHK starts up.

The whole GUI is still rough around the edges, so don't be too surprised if something breaks. If it does, kindly open a detailed issue on GitHub so I can fix the error. :) And don't feel shy making feature requests, either!

What is LPHKscript? [Table of Contents]

LPHKscript is a simple macro scripting language tailor made for LPHK. Syntax is closer to a shell/batch script than, say, JavaScript.

Any line that starts with a dash - will be considered a comment, and will be ignored by the syntax validator/script parser. Useful to add notes for yourself or others!

Only one script runs at a time, and there is a scheduling system for them. If a script is scheduled, it's button will pulse red. If the script is running, the button will flash red quickly. This is true for the 8x8 grid, however, the function keys cannot flash or pulse, as a hardware limitation. These keys will be bright orange for scheduled and bright red for running.

When you press a script button, if there is a script running, it adds the script to the queue. If no scripts are running, the script is added to the queue and the queue execution is started. Tapping a scheduled script's button will unschedule it, and tapping a running scripts button will kill it. If that sounds confusing, load up user_layouts/examples/all_delays_all_day.lpl and press a bunch of buttons.

Headers are commands that start with @ and go on the first line of a script. They are used to put the scripting engine into different "modes", allowing you to do some interesting things.

The @ASYNC Header [Table of Contents]

There is one exception to the scheduling system. If the script has the @ASYNC header, it will run in the background and will not interact with the other scripts. It can still be prematurely killed by tapping the button. If this is used, it must come before any other commands. Only comments and blank lines can come before it.

The @SIMPLE Header [Table of Contents]

This is a quick way to bind a controller button to a simple keypress of (argument 1). This has the equivalent code to:

@ASYNC
PRESS (argument 1)
WAIT_UNPRESSED
RELEASE (argument 1)

If this is used, all other lines in the file must either be blank lines or comments.

Commands List [Table of Contents]

Commands follow the format: COMMAND arg1 arg2 .... Scripts are just a text file with newlines separating commands.

  • DELAY
    • Delays the script for (argument 1) seconds.
  • GOTO_LABEL
    • Goto label (argument 1).
  • IF_PRESSED_GOTO_LABEL
    • If the button the script is bound to is pressed, goto label (argument 1).
  • IF_PRESSED_REPEAT_LABEL
    • If the button the script is bound to is pressed, goto label (argument 1) a maximum of (argument 2) times.
  • IF_UNPRESSED_GOTO_LABEL
    • If the button the script is bound to is not pressed, goto label (argument 1).
  • IF_UNPRESSED_REPEAT_LABEL
    • If the button the script is bound to is not pressed, goto label (argument 1) a maximum of (argument 2) times.
  • LABEL
    • Sets a label named (argument 1) for use with the *GOTO_LABEL commands.
  • OPEN
    • Opens the file or folder (argument 1).
  • REPEAT_LABEL
    • Goto label (argument 1) a maximum of (argument 2) times.
  • RESET_REPEATS
    • Reset the counter on all repeats. (no arguments)
  • SOUND
    • Play a sound named (argument 1) inside the user_sounds/ folder.
      • Supports .wav, .flac, and .ogg only.
    • If (argument 2) supplied, set volume to (argument 2).
      • Range is 0 to 100
  • SOUND_STOP
    • Stops all sounds currently playing.
    • If (argument 1) supplied, fading for (argument 1) milliseconds and then stops the sounds.
  • WAIT_UNPRESSED
    • Waits until the button the script is bound to is unpressed. (no arguments)
  • WEB
    • Open website (argument 1) in default browser.
  • WEB_NEW
    • Open website (argument 1) in default browser, try new window.
  • PRESS
    • Presses the key (argument 1).
      • See valid key names below.
  • RELEASE
    • Releases the key (argument 1).
      • See valid key names below.
  • RELEASE_ALL
    • Releases all pressed keys, including those pressed by other scripts. (no arguments)
  • STRING
    • Types whatever text comes after it.
  • TAP
    • Taps the key (argument 1).
      • See valid key names below.
    • If (argument 2) supplied, tap (argument 2) number of times.
    • If (argument 3) supplied, delay (argument 3) seconds before releasing each time.

Mouse Movement [Table of Contents]

  • M_LINE
    • Move the mouse in a line from absolute point (argument 1),(argument 2) to absolute point (argument 3),(argument 4).
    • If (argument 5) supplied, delay (argument 5) milliseconds between each step.
    • If (argument 6) supplied, move (argument 6) pixels per step.
      • If not supplied, assumed to be 1
  • M_LINE_MOVE
    • Move the mouse cursor in a line (argument 1) horizontally and (argument 2) vertically, relative to current position
    • If (argument 3) supplied, delay (argument 3) milliseconds between each step.
    • If (argument 4) supplied, move (argument 4) pixels per step.
      • If not supplied, assumed to be 1
  • M_LINE_SET
    • Move the mouse cursor in a line to absolute point (argument 1),(argument 2)
    • If (argument 3) supplied, delay (argument 3) milliseconds between each step.
    • If (argument 4) supplied, move (argument 4) pixels per step.
      • If not supplied, assumed to be 1
  • M_MOVE
    • Moves the mouse cursor (argument 1) horizontally and (argument 2) vertically, relative to current position.
  • M_RECALL
    • Sets the mouse position to the last location stored with M_STORE.
      • Will not do anything if M_STORE has not been called in that script.
  • M_RECALL_LINE
    • Move the mouse cursor in a line to the last location stored with M_STORE.
      • Will not do anything if M_STORE has not been called in that script.
    • If (argument 1) supplied, delay (argument 1) milliseconds between each step.
    • If (argument 2) supplied, move (argument 2) pixels per step.
      • If not supplied, assumed to be 1
  • M_SCROLL
    • Scrolls the mouse vertically by (argument 1).
    • If (argument 2) supplied, scroll horizontally by (argument 2).
  • M_SET
    • Sets the absolute cursor position to (argument 1) horizontal and (argument 2) vertical.
  • M_STORE
    • Stores the current mouse position for use with the M_RECALL* commands.

For the PRESS, RELEASE, and TAP commands, all single character non-whitespace keys and the following key names are allowed:

  • alt
  • alt_gr
  • backspace
  • caps_lock
  • cmd
  • ctrl
  • delete
  • down
  • end
  • enter
  • esc
  • f1 - f24
  • home
  • insert
  • left
  • menu
  • mouse_left
  • mouse_middle
  • mouse_right
  • mute
  • next_track
  • num_lock
  • page_down
  • page_up
  • pause
  • play_pause
  • prev_track
  • print_screen
  • right
  • scroll_lock
  • shift
  • shift_r
  • space
  • tab
  • up
  • vol_down
  • vol_up

Known Issues / Troubleshooting [Table of Contents]

  • The USB connection on the Launchpads, quite frankly, suck. If the angle is wrong, the Launchpad may receive power, but will not be able to transmit or receive data. While using the Launchpad, if you wiggle the connection somehow, it will straight up break the MIDI library I use. You will have to do the following:
    • Click on "Launchpad > Disconnect from Launchpad xxx..."
    • Unplug your Launchpad and wait about 5 seconds for the capacitors inside the Launchpad to drain. (It stays powered for a few seconds after losing it's connection, we want it dead as a doorknob)
    • Connect the Launchpad via USB
      • If you see the rainbow wipe effect and are left with no lights on, the connection is good
      • If the pad has psychedelic waves of colors exploding everywhere, it is getting power but cannot transmit or receive data. Try again, maybe with a different cable
      • If it does not light up at all, try again with a different cable or USB port
    • Click on "Launchpad > Redetect...". This will kill the program and restart it. This resets the MIDI library
    • If this does not fix the problem, or if the LP can connect and light up, but not receive input:
      • Try a different cable
      • Try a different USB port
      • Unplug and restart the program manually
      • Maybe restart your computer?
      • At this point IDK, maybe the USB on your Launchpad needs to be replaced.
  • If your game/application does not detect mouse movements, see if there is an option to turn off "raw input" in the settings. This setting bypasses all software and reads directly from the mouse, which you don't want for this.

In order of priority:

  • Set unbound buttons to null in .lpl files
    • Thank you MatijaK from the Discord for reminding me about this!
  • Add splash screen to PyInstaller executable, for feedback while loading
    • This feature of PyInstaller is in development at this very moment by Chrisg2000 and others Once it's done, I can do this!
  • Re-factor to use PyAutoGui
    • Adds support for more keys
      • For example, 5 and num5 are different, where keyboard says they are the same
    • May fix root issues on Linux
    • Will make everything just easier and cleaner, it's a library for automation in Python
  • Add @LOAD_LAYOUT header command to load a specified layout
    • Basic functionality (BETA, undocumented)
    • Check if layout currently exists when binding to a button (incl during load layout)
      • If not, prompt user if they want to continue anyway
    • Add option to override save changes prompt
  • Temporary fix for LP classic, make use colors from function rows (orange, red)
  • Add script status icons (bound, playing, queued)
    • Create icons
    • Draw icons
    • With this, allow buttons to be bound with the light off
  • Add startup config file
    • Default layout specification
    • Auto connect overide
    • Force launchpad model setting
  • Add more sound commands
    • Use different sound library that supports playing an arbitrary number of sounds, and controlling each sound individually while it plays
    • Add optional label argument to SOUND
    • Add SOUND_VOLUME to set the sound volume by label
    • Add SOUND_STOP to stop playing sound by label and delete the sound label
    • Add SOUND_ALL_* commands to stop/change the volume of all sounds
  • Let SOUND use spaces in it's path if it has double quotes around it
  • Let program function as a layout editor without LP connection
    • Would probably be easier to write a "Dummy LP" class
  • Make an installer for Linux
    • Should be a .deb installer package
    • Should use a conda environment created from an environment.yml file
    • Should copy LPHK files into an appropriate directory
    • Should give options to add various shortcuts
  • Add temporary command __M_PRINT_POPUP__ that gives a pop-up with the current cursor position
  • Option to minimize to system tray
    • Tkinter does not provide a way to do this. There may be Windows-specific extentions I can use, but maybe not.
  • Add auto-update feature using git
    • There will be a VERSION file in the main directory with the version string
      • This can be polled at https://raw.githubusercontent.com/nimaid/LPHK/master/VERSION
        • For example: wget -qO- https://raw.githubusercontent.com/nimaid/LPHK/master/VERSION
    • This will be displayed in the Help > About LPHK dialog.
    • If this string does not match the newest one at the above link, prompt to update
  • Make PRESS, RELEASE, TAP, and @SIMPLE accept multiple keys
    • Will accept multiple arguemnts seperated by spaces
    • Will be pressed in the order arg1, arg2... and unpress in the order ...arg2, arg1
  • Add percentage of screen width/height option to the M_* commands
  • Add SCRIPT command to run (argument 1) script in the user_scripts folder (like a function!)
  • Add settings menu to configure the startup config
  • Add more color customization
    • Make new fields in the .lpl layout format
      • Add run_color to set the "running" color
        • Default is red (255, 0, 0)
      • Add schedule_color to set the "scheduled" color
        • Default is red (255, 0, 0)
      • Add run_color_mode to set the "running" color mode
        • flash is a quick blinking (default)
        • pulse is a slow fade in and fade out
        • solid is coninuously on
      • Add schedule_color_mode to set the "scheduled" color mode
        • pulse is a slow fade in and fade out (default)
        • flash is a quick blinking
        • solid is coninuously on
    • Add more selectors to script entry window
  • Add a Sound menu with Choose default output device... option
  • Refactor code to make LPHKscript functions in auto-implementing modules, for ease of delevopment
    • A new testing branch will be created while the functional code is re-worked. To avoid merging issues, pull requests may have acceptance delayed until the refactor is complete.
    • There are a few complex refactoring tasks required for this, I will be crossing them off here on the testing branch:
      • Make a killable delay/time library that monitors thread kill flags
      • Port keyboard functions over to LPHKfunction modules
      • Make commands.py module to house the actual command logic
      • Move @SIMPLE to keyboard module.
        • Allow F['COMMAND']['macro'] = True to disallow other non-comment lines in the script. Default is False.
          • Macros will automatically have _ added to the beginning (@ will only be for headers)
          • validate_script() will take care of making sure macros are alone (after comment/nl stripping)
        • Allow F['COMMAND']['macro_async'] = True to enable async on a macro. Default is False, ignored if not a macro.
          • When importing functions on startup, make a dict to keep track of what macros are async
          • scripts.py will have a run_async dict to keep track of if a script is async
          • (Comments/nl stripped) During scheduling of the script, if first line is @ASYNC or is an async macro (1 functional line), then run_async[x][y] is set, otherwise unset
      • Write the importer library (test standalone w/ simple delay)
      • Lobotomize the program (read: remove the hellish logic in scripts.py)
      • Integrate the importer into the main program (scripts.py)
      • Find and kill all of the bugs
      • Port the rest of the old logic to LPHKfuction modules
      • Deal with the Pandora's box that porting those functions will open (this list will probably grow)
      • Make a way for modules to use standard commands, and to use other modules
      • Take a drink and merge the branches
  • Allow named arguments for certain commands
  • Add a Choose default MIDI device option to the Sound menu. (For multiple launchpads plugged in)
  • Add a third argument to SOUND for overriding the default sound device
  • Add variables and mathematical evaluation (mostly done!)
  • Add conditional jumps based on value comparisons (Would this make LPHKscript Turing complete? :D)
  • Add syntax highlighting
  • Add GUI scaling
  • Full support for Launchpad Pro
    • The lack of tactile feedback, inability to utilize the pressure sensitive inputs (launchpad.py limitation), and inconvenient function keys where the hand rests makes support for the LP Pro a lower priority.
  • Add generalized macro recorder wizard
  • Make Add Command... menu that acts as a guided helper for making commands
  • Add mouse event capture prompts to Add Command... menu boxes
  • Add keyboard event capture (incl. unknown keycodes) to Add Commands... menu boxes
  • Add CMD command to run OS commands
    • Make multi-level scary warning dialog boxes when binding to a button (incl during load layout)
    • Give option (and strongly recommend its use) for users to run command once and verify it does what they want before binding to button (incl during load layout)
  • MIDI output command? (low priority due to LPMM, an older project of mine that I no longer have time for due to LPHK)
  • Support for Launchpad MkII
  • Events system
  • Colors system
  • LPHKScript base iteration
  • Keyboard lib base
  • Proof of concept demo
  • Saving/Loading
  • Sound functionality
  • Basic GUI
  • Save/load single scripts in GUI
  • Script entry error checking
  • Add launchpad connection menu
  • Add M_MOVE, M_TAP, M_SCROLL, and M_SET commands
  • Add M_PRESS, M_RELEASE, and M_TAP commands
  • Put save/load script into menu
  • Add M_LINE, M_LINE_SET, and M_LINE_MOVE commands
  • Add a WAIT_UNPRESSED command that delays while the button the script is bound to is pressed
  • Add @ASYNC header command to run script independent of other scripts
  • Add launchpad connection status indicator/remove popups
  • Add commenting script lines
  • Make pressing a running/queued button cancel/terminate execution
  • Make queued/playing buttons blink instead of be solid (Big shout out to FMMT666 for adding the features I needed to launchpad.py!)
  • Make user defined colors RGB
  • Add RGB color selector
  • Add LABEL command
  • Add IF_PRESSED_GOTO_LABEL command to jump from this line to a LABEL if the key is still pressed
  • Add GOTO_LABEL command
  • Add IF_UNPRESSED_GOTO_LABEL command to jump from this line to a LABEL if the key is unpressed
  • Add REPEAT_LABEL command to jump from this line to a LABEL n number of times max
  • Add IF_PRESSED_REPEAT_LABEL command to jump from this line to a LABEL if the key is still pressed n number of times max
  • Add IF_UNPRESSED_REPEAT_LABEL command to jump from this line to a LABEL if the key is unpressed n number of times max
  • Add M_STORE, M_RECALL, and M_RECALL_LINE functions to remember where the mouse was before execution
  • Fix syntax checking being done in main_logic() instead of the, you know, syntax checker?
  • Merge SP_ functions into smart versions of their single-character counterparts
  • Add feature to syntax checking for SOUND to check if file exists/is usable
  • Do syntax checks on loading a layout
  • Add @SIMPLE header for simple keybinding of single keyboard keys
  • Merge M_TAP, M_PRESS, and M_RELEASE commands into their keyboard counterparts
  • Add button move/swap/copy feature
  • Fix button highlighting clipping at screen edges
  • Add warning prompts to move/copy
  • Add "Do you want to save your layout?" popup on exit if layout is unsaved.
  • Add save layout if changed prompt to load/new layout
  • Do not prompt to save blank layout
  • Do not warn about moving/copying to the same button
  • Make script being edited highlighted
  • Fix weird bug where GOTO and DELAY didn't obey a kill command (caught on video)
  • Add OPEN command to open folders and files
  • Add RELEASE_ALL command
  • Add RESET_REPEATS command to reset the counter on all repeats
  • Basic support for Launchpad Classic/S/Mini
    • Thanks to Patreon patron Korbinian Maag for fully funding the purchase of a LP Mini for developing this feature!
    • Includes Behringer CMD Touch TC64 in Novation compatibility mode
  • Add partial Pro support (left and bottom rows not enabled)
    • A huge shoutout to MiniStumpy Bloopers in the Discord, who was able to find out that adding this feature was actually fairly simple! I really need a Pro to develop with.
  • 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.

lphk's People

Contributors

dependabot[bot] avatar dmac31415 avatar duncte123 avatar erikskinnari avatar lyiriyah avatar nimaid avatar nullmember avatar silencx avatar snags avatar still34 avatar thetimewalker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lphk's Issues

shift_r doesn't exist

So currently I'm trying to bind vrchat gestures to my launchpad, these keybinds are:
shift+f1 through 8 for left hand
right shift+f1 through 8 for right hand

left hand works like a dream with the code:

PRESS shift
PRESS f1
WAIT_UNPRESSED
RELEASE shift
RELEASE f1

right hand however cannot be bound since when i replace shift with shift_r it comes up with an error message saying the key does not exist.

LPHK on Mini?

I absolutely love the concept of LPHK, but I only own a Launchpad Mini. Is it possible you can work towards a solution for Launchpad Mini? And if so, could I request a rough estimate on when I could use LPHK with Mini?
Thanks in advance.

Edit: I apologise, I had not read the readme thoroughly.

Shift key automatic keyup when another key is tapped

Script:

PRESS win
PRESS shift
TAP right
RELEASE shift
RELEASE win

Expected behavior from JS Key tracker (https://unixpapa.com/js/testkey.html):

keydown  keyCode=91  ([)   which=91  ([)   charCode=0        
keydown  keyCode=16        which=16        charCode=0        
keyup    keyCode=39  (')   which=39  (')   charCode=0        
keyup    keyCode=16        which=16        charCode=0        
keyup    keyCode=91  ([)   which=91  ([)   charCode=0        

91 is win, 16 is shift and 39 is right arrow

Actual behavior:

keydown  keyCode=91  ([)   which=91  ([)   charCode=0        
keydown  keyCode=16        which=16        charCode=0        
keyup    keyCode=16        which=16        charCode=0        
keyup    keyCode=39  (')   which=39  (')   charCode=0        
keydown  keyCode=16        which=16        charCode=0        
keyup    keyCode=16        which=16        charCode=0        
keyup    keyCode=91  ([)   which=91  ([)   charCode=0  

Notice the 2 extra lines at line 3 and 5. I've tried variants of PRESS, TAP, ASYNC to no avail.

Edit: I'm using the Launchpad Pro (but other shortcuts seem to work fine, for example this script works fine:

PRESS ctrl
PRESS shift
TAP n
RELEASE shift
RELEASE ctrl

DELAY 0.5

PRESS ctrl
TAP k
TAP o
RELEASE ctrl

Repeat command while button is pressed

Hi!
Firtst of all, thank you ever so much for this project! I really appreciate this ๐Ÿ‘

Is there a function which allows for the command to repeat while the button is pressed?
For instance with vol_down.

While button is pushed down, repeat @simple vol_down until button is released.

Makes sense?

How to bind numeric keys?

Hi @nimaid

I was wondering if there is a way to map numeric keys.
If i do a @simple 4, the 4 on the normal keyboard will be pressed, but I can find the way to press 4 on the numeric block of the keyboard.

Best regards
Rasti

Characters which require escaping in Python scripts cannot be used for TAP or PRESS.

I'm unable to use , /, or ' as valid targets for a TAP or PRESS command. I believe this is because these characters are considered "special" and require escaping in order to use them as plain characters.

Upon checking in pynput using a short script you can see what pynput sees when you type a backslash:

from pynput import keyboard

def on_press(key):
... try:
... print('alphanumeric key {0} pressed'.format(
... key.char))
... except AttributeError:
... print('special key {0} pressed'.format(
... key))
...
def on_release(key):
... print('{0} released'.format(
... key))
... if key == keyboard.Key.esc:
... # Stop listener
... return False
...

Collect events until released

... with keyboard.Listener(
... on_press=on_press,
... on_release=on_release) as listener:
... listener.join()
...
Key.enter released
alphanumeric key \ pressed
'\' released
alphanumeric key \ pressed
'\' released

Note the escaped version of the backslash: '\'.

Using mp3 sounds

I am putting a mp3 sound into the examples file and using this code:
SOUND examples\meme.mp3
Keep getting a error message saying that it can not be found.
I have the default wav files in there and they work fine with the:
SOUND examples\airhorn.wav
And it is in the exact same file location.

Not able to detect my launchpad

I have my novation launchpad MK2 plugged into my galliumos linux laptop, and for some reason, it can't be detected. here is the log:

chrx@chrx:~/Desktop/LPHK-master$ python3 LPHK.py
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
ALSA lib conf.c:3523:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so
ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
ALSA lib conf.c:3523:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so
ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default
Traceback (most recent call last):
File "LPHK.py", line 58, in
main()
File "LPHK.py", line 56, in main
shutdown()
File "LPHK.py", line 49, in shutdown
os.execv(sys.executable, [""" + sys.executable + """] + sys.argv)
FileNotFoundError: [Errno 2] No such file or directory

Here is what it looks like when I type lsusb

chrx@chrx:~/Desktop/LPHK-master$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 8087:0a2a Intel Corp.
Bus 001 Device 002: ID 04f2:b567 Chicony Electronics Co., Ltd
Bus 001 Device 015: ID 1235:0069 Focusrite-Novation
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Any help is appreciated. Thank you.

Possible to load new layouts?

Any way to make it so i can key in to load certain layouts on button press so i can switch between layouts faster?

Simply assigned keys are not accepted in the game

Hi!
I assigned simple buttons to the launchpad.
I want to use it with the game Elite: Dangerous.

If I press the assigned keyboard shortcuts on the Launchpad in a note, then I get the result directly. This means that the inputs via the launchpad actually work like a keyboard.

However, this does not work in the game.
The game does not accept any buttons from the launchpad.

Am I missing something here?

Typo in LPHK.py

The is a typo in the shutting down function.
Wanted to commit a branch for it but that doesn't seem possible so here's the typo

Line 50 :
sys.exit("[LPHK] Sutting down...") -> sys.exit("[LPHK] Shutting down...")

_tkinter.TclError: couldn't recognize data in image file "resources/info.png"

I cloned this on my mac. Python 3.6 in a virtual environment. Installed the dependencies, and then ran the script as in the instructions and get this error trace.

Traceback (most recent call last):
File "LPHK.py", line 56, in
main()
File "LPHK.py", line 52, in main
window.init(lp)
File "/Users/jandrews/Projects/innovation-cmd/LPHK/window.py", line 26, in init
make()
File "/Users/jandrews/Projects/innovation-cmd/LPHK/window.py", line 335, in make
app = Main_Window(root)
File "/Users/jandrews/Projects/innovation-cmd/LPHK/window.py", line 33, in init
self.info_image = tk.PhotoImage(file="resources/info.png").subsample(2, 2)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/init.py", line 3539, in init
Image.init(self, 'photo', name, cnf, master, **kw)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/init.py", line 3495, in init
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "resources/info.png"

Volume Controls Not Working on Mac

The volume controls are not working on Mac.

System Version: macOS 10.15.5
Script: TAP vol_up
Log:
---------------- BEGIN LOG 15/07/2020 14:23:12 ----------------
LPHK - LaunchPad HotKey - A Novation Launchpad Macro Scripting System
Version: 0.3.0
Platform: Macintosh
Is compiled executable: False
Is portable: True
Operating path: /Users//downloads/LPHK-0.3.0
User path: /Users//downloads/LPHK-0.3.0
Program file path: /Users//downloads/LPHK-0.3.0
Program file: /Users//downloads/LPHK-0.3.0/LPHK.py
Log file (this file): /Users//downloads/LPHK-0.3.0/LPHK.log

pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html

[scripts] (0, 7) No script running, starting script in background...
[scripts] (0, 7) Now running script...
[scripts] (0, 7) Tap key vol_up
[scripts] (0, 7) Script done running.

You must be root to use this library on linux when using the default layout's volume function on Arch

The basic steps to the error where:

  1. Installing using the beta installer
  2. Changing the env to the LPHK env
  3. Running LPHK.py (with plugged in launchpad)
  4. Loading the default example layout

The following error occurs when i press the left, light up and down keys:

[scripts] (2, 0) Starting asynchronous script in background...
[scripts] (2, 0) Now running script...
[scripts] (2, 0)    Simple keybind: prev_track
Exception in thread Thread-67637:
Traceback (most recent call last):
  File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/tmp/LPHK-master/scripts.py", line 523, in run_script
    idx = main_logic(idx)
  File "/tmp/LPHK-master/scripts.py", line 492, in main_logic
    kb.press(key)
  File "/tmp/LPHK-master/kb.py", line 23, in press
    keyboard.press(key)
  File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/__init__.py", line 396, in press
    send(hotkey, True, False)
  File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/__init__.py", line 383, in send
    _os_keyboard.press(scan_codes[0])
  File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/_nixkeyboard.py", line 158, in press
    write_event(scan_code, True)
  File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/_nixkeyboard.py", line 144, in write_event
    build_device()
  File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/_nixkeyboard.py", line 109, in build_device
    ensure_root()
  File "/home/MYUSER/.conda/envs/LPHK/lib/python3.7/site-packages/keyboard/_nixcommon.py", line 174, in ensure_root
    raise ImportError('You must be root to use this library on linux.')
ImportError: You must be root to use this library on linux.

Trying to start LPHK with sudo brings a whole other problem along (tried it as suggested by @nimaid ):

(LPHK) [MYUSER@HOSTNAME LPHK-master]$ sudo /home/MYUSER/.conda/envs/LPHK/bin/python /tmp/LPHK-master/LPHK.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
Traceback (most recent call last):
  File "/tmp/LPHK-master/LPHK.py", line 58, in <module>
    main()
  File "/tmp/LPHK-master/LPHK.py", line 53, in main
    init()
  File "/tmp/LPHK-master/LPHK.py", line 33, in init
    sound.init(PATH)
  File "/tmp/LPHK-master/sound.py", line 16, in init
    m.init()
pygame.error: No available audio device

My setup is:

  • Laptop running Arch Linux
    • I use i3 as my window-manager
    • I have alsamixer and pulseaudio installed for everything related to audio i/o
  • Launchpad MK2
  • The LPHK installation is located in /tmp/LPHK-master
  • I have sudo rights

Please comment if additional information is needed - I'll try to respond asap.

LPHK Crash when redetecting Launchpad

OS: Ubuntu 18.04
Launchpad: MK2
Python versions (python --version)
System: Python 2.7.15+
Conda: Python 3.7.5

When pressing connect to launchpad the following error occurs, when switching usb ports and pressing redetect the program crashes
image

Program output (full output):

duncte123@duncte123 ~> bash
duncte123@duncte123:~$ conda activate LPHK
(LPHK) duncte123@duncte123:~$ python --version
Python 3.7.5
(LPHK) duncte123@duncte123:~/Desktop/LPHK$ git pull
remote: Enumerating objects: 58, done.
remote: Counting objects: 100% (58/58), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 53 (delta 37), reused 35 (delta 19), pack-reused 0
Unpacking objects: 100% (53/53), done.
From github.com:nimaid/LPHK
   d52345a..cc4d1ca  master     -> origin/master
Updating d52345a..cc4d1ca
Fast-forward
 README.md                        | 304 +++++++++++++++++++++------------------
 install_beta/install_windows.bat |  57 ++++----
 window.py                        |  15 +-
 3 files changed, 210 insertions(+), 166 deletions(-)
(LPHK) duncte123@duncte123:~/Desktop/LPHK$ python LPHK.py 
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
ALSA lib conf.c:3558:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib/alsa-lib/libasound_module_conf_pulse.so: libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fa47d9ed740 (most recent call first):
Aborted (core dumped)
(LPHK) duncte123@duncte123:~/Desktop/LPHK$ 

LSUSB output:

duncte123@duncte123 ~> lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 8087:0a2b Intel Corp. 
Bus 001 Device 002: ID 0bda:58d2 Realtek Semiconductor Corp. 
Bus 001 Device 004: ID 1235:0069 Focusrite-Novation 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
duncte123@duncte123 ~> 

Find mouse position

I'm having issues to get the mouse coordinates of where I want it to click.

This issue could be solved by adding a command to LPHK Script, that displays the current mouse coordinates somewhere.

As an example:
M_COORD would show the current coordinates of the mouse in a pop-up window

If you could add this command, it would really help me programming my macro keys.

Problem in SOUND/How to toggle keys

If I use SOUND, the sound file's pitch is lowered when it is played. And plus how can i toggle keys by commands? I want to toggle Q key(i'll use autohotkey as ctrl+F23 as there isn't q in LPHK) for voice chat in games, but I don't know how. By the way is toggling keys is supported?

+) plz make toggling lights

Windows + L doesn't work

I tried to set up a button to lock my computer using the key combination Windows + L.
The Code I used looks like this:
PRESS windows
TAP l
RELEASE windows
However it didn't do anything, but when I used a combination like Win + E (for opening a file explorer) it worked just fine...

LP Mini not working.

Hooked up my LP Mini and tried to connect but connection failed after many redetects.

Sending SOUND to specific output

Hi it would be nice if you could make it so that the sound could be played out of multiple outputs. so for example one through my headphones and one thorugh my mic (so that it would be an actual soundboard)
ty

Add function for layout

Hi,
I have an idea :
Make a function to change layout when you click on a button.
They can be good to have multiple board and easy to change layout.

(sorry for my english, i'm french)
great project

STRING accents problem

Hey !
When i use the "STRING" argument, i can't use accents like:
"STRING รฉ". The "รฉ" simply not appear :/

(sorry for my english, i'm french)

Thanks,
Mathitux

Loading a layout on startup

I've been using the application for a month now. And everytime I boot up, I need to launch the app, press the Live Mode pop-up for Launchpad Pro and then proceed to load my layout. I was thinking maybe there is a way to automate this, or even just load the last opened layout on the next boot.

Custom Launchpad Pro firmware isn't recognized properly

Hi Ella,

I wanted to try out LPHK with my Launchpad Pro, with a custom firmware installed on it (https://github.com/mat1jaczyyy/lpp-performance-cfw) and when I try to launch LPHK, it recognizes my LP as a Launchpad Classic/Mini/S and first of all, the layout is all messed up and the buttons don't do anything. I'm also encountering this error when first starting LPHK.
Exception in thread Thread-2: Traceback (most recent call last): File "D:\Programmi\Miniconda3\envs\LPHK\lib\threading.py", line 926, in _bootstrap_inner self.run() File "D:\Programmi\Miniconda3\envs\LPHK\lib\threading.py", line 1177, in run self.function(*self.args, **self.kwargs) File "D:\Git Repositories\LPHK-master\lp_events.py", line 28, in run pressed[x][y] = False IndexError: list index out of range

I don't know what to do about it.

TheLifeGamingYT

Suggestion (Sorry for issue area)

Add the function to have a button to switch to another profile, or have the ability to open the profile with open file ability and load it up that way. I would love to have my right circular keys as buttons for 8 different profiles.

Install hell on Linux

@nimaid
OS: Ubuntu 18.04, fresh install. (Remember this)
PC: Thinkpad T430, i5 3320m, 16GB RAM, Samsung 256GB SSD
LP: LP MKII
Issue: I run the installer, it installs Conda fine. But when it tries to install LPHK, it doesn't create directories in ~/.conda and bitches to me that I don't have write permissions. I run as root, same issue. I run chown lyiriyah .conda. Still bitches. So I create the directories, change the ownership to me and run it again. It completes successfully. I run RUN.bash and it loads and doesn't detect my Launchpad. Happy fun. I am installing Conda myself as I write this, maybe that will change something.

Wrong keybinds?

Today i made a layout to play fortnite with my launchpad mini and i had two problems:

I assigned "TAP d" to a key and when i ran it... it muted the sound of the computer;
I assigned "TAP g" to another key and it started playing music in spotify.

I once tested this and i had no problems.

My OS: Windows 10

pip.exe not opening?

Okay, I get this isn't about your software but it still baffles me. When I open pip.exe, it opens, and closes immediately.

Auto-Importing Functions

Hello everyone,
The idea is to have a main script that at a fixed point (startup) wuold read all files in a sub-folder (/commands) and if the file has the right format (normal .py script + a specific header) it would import it as an available command/function in the LPHK language.

The script will check for the libs that it needs to run that specific script and install it via pip.

In the header, there will be a way to rename functions.
When using an importend function you need to use the name of the file "x" and the name of the function "y".
In the LPHK script, you will need to write x.y as a command.
When importing a file, the script will create a dictionary and associate a specific command with a custom name.
Something like function['WEB_NEW']=Web.open_ new.
Thanks to this, you'll be able to use the custon name and make the LPHK script look "nicer".

Autostart

Is there any option to autostart LPHK on PC boot load a config/layout and run it in the Background
Is there anything planed for the future?

Allow parameter for OPEN

Can you allow parameters for OPEN? I like to start serialsend.exe and give lots of info to the program. At the moment I get error, file not found.

Looping while pressing

Hello

Is there a way to loop something while I press it? I want a volume up button that keeps going up untill I release the button.

Thanks in advance

PRESS and TAP are not global on windows

While testing the program out on windows I noticed that the key commands like TAP, PRESS and @SIMPLE are only executed for the window that is currently focussed, this breaks using LPHK for stuff like controlling obs while you are streaming

LPHK.py not opening, at all

It opens a command line for a split second, and then closes, with no output

I tried python LPHK.py, and got:
python LPHK.py
File "", line 1
python LPHK.py
^
SyntaxError: invalid syntax

With python3 LPHK.py:
python3 LPHK.py
File "", line 1
python3 LPHK.py
^
SyntaxError: invalid syntax

For some reason it won't allow spaces at the starts of lines, thanks GitHub

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.