GMSnip
A downloadable tool for Windows
An experimental tool for handling overpowered text snippets for Gamemaker (or anything else, really), using the power of Python. For Windows only.
Latest version: 0.21
DISCLAIMER: GMSnip is provided as-is. Use at your own risk.
Features
- Create simple substitutions (type a tag inside Gamemaker, GMSnip replaces it with a different text).
- Create substitutions with parameters (type a tag inside Gamemaker, a form will popup where you can type or select the value of the parameters, and GMSnip will fill out the text template substituting the variables with the typed values).
- Create complex substitutions using the power of Python (type a tag inside Gamemaker, execute a custom Python function to process that tag and return whatever you need, with optional parameters).
Bonus: change a config parameter and use it elsewhere, not just in Gamemaker.
Instructions
Unzip the file to a directory of your choosing and run gmsnip.exe.
Close the window or use CTRL+BREAK (or ESC if configured that way - see below) to stop it.
Details
Configure tags and substitutions
- Edit GMSnip's tags and substitution rules by editing
rules.json
. It already comes with example rules of the three kinds.
Each key of the JSON file will correspond to the tag as you type it in Gamemaker.
Every key will have the following structure:
Key | Description | Details |
"description" | A text description of what the rule does. | |
"snippet" | The corresponding text to substitute. You can add variables enclosing them with double curly braces: {{my_var}} Each variable must correspond to a parameter in the "params" key. | If you want to use invalid JSON characters, you must escape them with a backslash. For example, if you need a backslash, type \\. Check out this link for more. |
"params" | A structure containing one key per parameter (with the parameter name) and the following keys:
| GMSnip will automatically show a form if at least one parameter is configured. All parameters will be available both to the snippet (as variables enclosed in double curly braces, as described above) and to the function (as a Python dictionary - see examples as well as text below, for more) |
"function" | The name of a function which is defined inside the gmsnip Python package file. | You can have both a function and a snippet template. If so, the function will process first, and then the variables (if any left) will be substituted for the available parameters. |
Configure advanced substitutions
- Create your custom Python functions inside the
gmsnip
Python package file (__init__.py
)
You must define your function with the following signature:
- Inputs: the snippet text, and the parameters dictionary.
- The snippet text will be a Python string.
- The parameters dictionary will be a dictionary of StringVar (from tkinter). This means you will need to use .get() to actually resolve the value of any of them. See the examples for more details.
- Output
- It must return a string with the processed text.
- Recommended to enclose between try...except blocks and return a default string (such as "Error"), if something wrong comes up.
Configure the behavior of GMSnip
- Configure GMSnip's general options, by editing
config.json
Parameter | Description | Default Value |
"window_name" | Establishes the text GMSnip will search for in order to identify in which window to perform its magic. | "Gamemaker" |
"keyboard_polling_rate_seconds" | Sets the number of seconds GMSnip waits between each check of keyboard strokes. | "1" |
"input_rate_pause_seconds" | Sets the number of seconds GMSnip will wait before sending keystrokes to the target application | "0.01" |
"send_key_pause_seconds" | Sets the number of seconds GMSnip will wait after activating the target window and after deleting the typed tag, before typing the processed text | "0.25" |
"end_on_esc" | Defines whether the ESC key stops GMSnip ("True") or not ("False") | "False" |
How does GMSnip work?
- It uses PyDirectInput to listen to keyboard strokes every X seconds (using sched).
- GMSnip does NOT store or send keyboard strokes anywhere.
- It uses PyAutoGUI and PyGetWindow to interact with the first window available with the specified string (see config.json above).
- It reads the JSON to match any tag to the currently processed text.
- If there's a match, it checks whether there are parameters defined; if so, uses tkinter to create a form and parses the specified parameters to create the input widgets. If not, then it proceeds.
- If there's a function, it executes that function over the snippet text and the parameter values.
- Then it substitutes any remaining variables in the processed string with the value of the parameters.
- Finally, it deletes the tag in the target window and pastes the processed text.
Notes/FAQ
- For now, it assumes the tags are of the form :tag (or any other tag you can completely select with two CTRL+SHIFT+LEFT keystrokes)
- If the typed tag has a configured parameter, but the form does not popup, check your Windows taskbar. It should be there.
- If the console window closes automatically, an error happened. Check your configuration file to make sure it is a valid JSON (i.e. no trailing or missing commas, something not enclosed in double quotes, etc.)
Credits
- Credits to the authors of the different Python libraries.
- Thanks to @FrostyCat for giving me the idea!
Download
Download
GMSnip 0.21.zip 57 MB
Leave a comment
Log in with itch.io to leave a comment.