How to Run Scripts with Mouse Gestures
Mouse Gestures: An Underutilized Feature
Mouse gestures have always been an underutilized feature. Similar to Virtual Reality helmets, they are undeniably useful and have the potential to become universal. However, unlike VR, which has seen substantial investment, mouse gestures remain relatively neglected. Even today, internet browser manufacturers hesitate to implement them in the base code, let alone provide a system-wide solution. Notably, Apple’s Hot Corners is an example of something similar being implemented, but it is not a comprehensive solution.
Casual users benefit the most from mouse gestures since they eliminate the need to remember text commands or navigate through menus. Instead, users can simply press a button and perform a hand movement. This feature can also be incredibly beneficial for programmers and IT administrators. Gone are the days when most tasks were performed in a terminal window, making the mouse redundant. Nowadays, many tasks are executed in graphical interfaces.
A particularly powerful and simple action is starting a script with a mouse gesture. In just half a second and with our eyes closed, we could perform tasks such as:
- Preparing the work environment: Starting multiple apps, resizing windows, and closing unnecessary processes.
- Clipboard management: Displaying a list of recent clipboard items for quick pasting.
- Screenshot tool: Capturing a screenshot and saving it to a predefined folder.
- New email shortcut: Starting an email client and opening a new message window with the recipient pre-filled.
- VPN connect/disconnect: Quickly connecting to or disconnecting from a VPN.
- Task automation: Running a predefined automation script, such as moving files to a backup location.
- Lock screen: Immediately locking the computer screen for security.
And much more. Imagination is the limit, as scripts can do almost anything, and modern Windows operating systems are very receptive.
All we need for these tasks is a desktop mouse gesture program.
About StrokesPlus
Since mouse gestures are not very popular, there aren’t many apps offering this functionality. Those that do often have slow development cycles. The app I recommend is StrokesPlus. Although it hasn’t received an update in almost a year, it remains a complete and bug-free software.
It’s best to download it directly from its website at strokesplus.net.
The program is simple yet powerful. It offers keyboard modifiers for every action, not just a single optional modifier for all actions. For instance, a right button swipe to the right could perform one action, a left button swipe to the right could do another, and a shift-right button swipe to the right could do yet another.
This dramatically increases the number of actions you can assign, unlike most other mouse gesture programs that force users to come up with complex and difficult-to-execute gestures. The more complex the gesture, the higher the chance of executing an incorrect action.
StrokesPlus uses Lua as a scripting language, allowing for a wide range of actions. The most basic use is generating keystrokes, such as ctrl+w, frequently used to close the current tab in programs. But it offers much more! Lua can interact with Windows APIs, enabling file operations, window management, process management, and system volume control.
Thanks to AI tools like ChatGPT, you don’t even need to know Lua or delve into Windows API commands to program these tasks. Simply ask, and you shall receive.
Setting Up a Mouse Gesture to Start a Python Script
-
Install StrokesPlus: After installation, restart your PC if necessary. Run the application. Its default state is minimized, with only a tray icon visible. Open the application window by clicking the tray icon.
-
Create a new action: In the StrokesPlus.net interface, go to the Actions tab. Click the New Action button.
-
Name the action: Give your action a descriptive name, such as My First System-Breaking Python Script.
-
Assign a gesture: Assign a mouse gesture to this action by drawing in the gesture box.
-
Add Lua script: In the Lua Script tab for the action, add the following Lua code to run your Python script through the virtual environment’s Python interpreter:
Make sure to replace “C:\path\to\myenv\Scripts\python.exe” with the actual path to the Python executable in your virtual environment, and “C:\path\to\your\script.py” with the actual path to your Python script.
Troubleshooting tips
- Permissions: Ensure your Python script has the necessary permissions to execute.
- Paths: Double-check all paths in your Lua script for accuracy.
- Virtual Environment Activation: Ensure you are using the correct path to the virtual environment’s Python executable.
Keep in mind that if you already use mouse gestures in browsers, they may conflict with system-wide StrokesPlus gestures. It’s best to disable the browser add-ons. Additionally, while playing games, you might accidentally trigger mouse gestures. If those gestures correspond to in-game keyboard shortcuts, you could disrupt your gaming session. It’s best to either close StrokesPlus before playing, or add the game to Ignore List in StrokesPlus
Extra advice
It is not recommended to bind critical scripts to mouse gestures. Always consider the consequences of accidentally starting a script, whether by you or someone else using your computer. Assume it will happen one day, and if the negative consequences are too high, avoid creating that gesture.
Ideal candidate scripts are those that:
- Do not require any fixing or require minimal fixing if executed accidentally.
- Are repetitive and need to be done frequently.
- Were previously executed manually in a cumbersome and inconvenient way.
Final word
Mouse gestures represent a powerful tool for enhancing productivity and simplifying complex tasks on your computer. By leveraging StrokesPlus and the techniques outlined in this article, you can create a personalized set of gestures that cater to your specific needs, whether you’re a programmer, IT administrator, or casual user. The ability to execute scripts, launch applications, and perform system operations with a simple mouse movement can significantly streamline your workflow and save valuable time.
However, it’s crucial to approach the implementation of mouse gestures with thoughtfulness and caution. Consider the potential consequences of accidental activation, especially for critical scripts or actions. Focus on creating gestures for repetitive, non-destructive tasks that genuinely enhance your efficiency. With careful planning and judicious use, mouse gestures can become an indispensable part of your computing toolkit, offering a glimpse into the intuitive, gesture-driven interfaces that may shape our digital future.