Ask me anything
Ithy Logo
Sign in to save

Enhancing StrokesPlus: Display Gesture Names and Clipboard Integration

Unlocking advanced features for seamless gesture control and clipboard management.

gesture control interface

Key Takeaways

  • Gesture Feedback Enhancement: Customize StrokesPlus to display gesture action names for improved user interaction.
  • Clipboard Integration: Implement scripts to retrieve the latest clipboard buffer, enabling dynamic command execution.
  • Seamless Program Execution: Develop a C++ bridge program to pass clipboard content as parameters to other executables.

Request A: Displaying Gesture Action Names in StrokesPlus

Understanding the Limitation

By default, StrokesPlus does not display the gesture action name while drawing a gesture. This limitation can hinder user experience by not providing immediate feedback on the gesture being performed.

Customizing StrokesPlus with Scripts

To overcome this, you can customize StrokesPlus using scripts to display the gesture action name. Below are the steps to achieve this:

Step 1: Access the StrokesPlus Action Editor

Open StrokesPlus and navigate to the Actions or Commands settings. Assign a specific gesture to an Execute Command action.

Step 2: Implement a Lua Script for Feedback

Use the following Lua script to display a message box with the gesture action name when a gesture is recognized:

local gestureName = action.Start
sp.MessageBox("Gesture Action: " .. gestureName, "Gesture Feedback")

This script concatenates the gesture's starting action with a message box, providing immediate visual feedback to the user.

Step 3: Assign the Script to the Gesture

Within the action editor, replace the executable name with the gesture name in the script. Ensure that the script is correctly linked to the desired gesture to display the appropriate action name.

Enhancing User Feedback

For a more subtle feedback mechanism, consider using notification balloons instead of message boxes. This can be achieved by modifying the script to utilize system notifications, ensuring that the user is informed without interrupting their workflow.


Request A: Retrieving the Last Clipboard Buffer

Using Lua Scripts for Clipboard Access

StrokesPlus does not natively provide a function to retrieve the last clipboard buffer directly. However, by leveraging Lua scripts within StrokesPlus, you can access and utilize clipboard content effectively.

Sample Lua Script for Clipboard Retrieval

local clipboardText = sp.getClipboardText()
-- Utilize clipboardText for subsequent actions or processing

This script captures the current clipboard text, allowing you to use it within your custom actions or pass it to external programs.

Integrating Clipboard Retrieval with Gestures

After retrieving the clipboard content, you can integrate this data with your gestures to perform dynamic actions based on the clipboard's state. For instance, triggering a specific program with the clipboard text as a parameter enhances automation and efficiency.


Request B: C++ Program to Handle Clipboard Content

Overview of the Bridge Program

The C++ program, named myprograme.cpp, serves as a bridge between the clipboard content and another executable, other_programe.exe. It retrieves the latest clipboard text and passes it as a command-line parameter to the designated program.

Complete C++ Code: myprograme.cpp

#include <windows.h>
#include <string>
#include <iostream>
#include <shellapi.h>

// Function to retrieve clipboard text
std::string GetClipboardText() {
    if (!OpenClipboard(nullptr)) {
        std::cerr << "Failed to open clipboard." << std::endl;
        return "";
    }

    HANDLE hData = GetClipboardData(CF_UNICODETEXT);
    if (hData == nullptr) {
        CloseClipboard();
        std::cerr << "No text data in clipboard." << std::endl;
        return "";
    }

    wchar_t* pText = static_cast<wchar_t*>(GlobalLock(hData));
    if (pText == nullptr) {
        CloseClipboard();
        std::cerr << "Failed to lock clipboard data." << std::endl;
        return "";
    }

    std::wstring wstr(pText);
    GlobalUnlock(hData);
    CloseClipboard();

    // Convert wide string to UTF-8 string
    int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
    std::string strTo( size_needed, 0 );
    WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
    return strTo;
}

int main() {
    std::string clipboardContent = GetClipboardText();
    
    if (clipboardContent.empty()) {
        std::cerr << "Clipboard is empty or couldn't be accessed." << std::endl;
        return 1;
    }

    // Construct the command to run other_programe.exe with clipboard content as parameter
    std::string command = "other_programe.exe \"" + clipboardContent + "\"";

    // Execute the command using ShellExecute
    HINSTANCE result = ShellExecute(nullptr, "open", "other_programe.exe", 
                                    ("\"" + clipboardContent + "\"").c_str(), nullptr, SW_SHOWNORMAL);

    if ((int)result <= 32) {
        std::cerr << "Failed to execute other_programe.exe." << std::endl;
        return 1;
    }

    return 0;
}

Explanation of the C++ Code

The program performs the following operations:

Step Description
1. Open Clipboard Uses OpenClipboard to access the system clipboard.
2. Retrieve Clipboard Data Obtains the clipboard data in CF_UNICODETEXT format for wide character support.
3. Convert to UTF-8 Converts the wide string to a UTF-8 encoded std::string for compatibility.
4. Construct Command Builds the command to execute other_programe.exe with the clipboard content as an argument.
5. Execute Command Uses ShellExecute to run the target program with the provided parameter.
6. Error Handling Checks for successful execution and handles errors appropriately.

Compilation Instructions

To compile the C++ program on Windows, use the following command with Visual Studio's Developer Command Prompt:

cl /EHsc myprograme.cpp /link /SUBSYSTEM:CONSOLE

This command compiles the source code with exception handling and links it as a console application.

Integrating with StrokesPlus

After compiling myprograme.exe, configure StrokesPlus to execute this program when a specific gesture is detected:

  1. Open StrokesPlus and navigate to the Actions settings.
  2. Assign the desired gesture to an Execute Command action.
  3. In the command line field, enter the full path to myprograme.exe, for example:
    C:\Path\to\myprograme.exe
  4. Ensure that other_programe.exe is accessible via the system PATH or provide its full path within the C++ code.

Enhancing Reliability and Security

To ensure the robustness of the integration:

  • Error Handling: Enhance the C++ program with comprehensive error checking for clipboard access and program execution to handle unexpected scenarios gracefully.
  • Input Sanitization: Sanitize the clipboard content to prevent command injection or execution of unintended commands.
  • Unicode Support: Ensure that the program correctly handles Unicode characters in the clipboard to support diverse text inputs.

Advanced Configurations and Best Practices

Optimizing Gesture Feedback

For a more streamlined user experience, consider the following enhancements:

  • Transient Notifications: Replace persistent message boxes with transient notifications or on-screen displays that do not disrupt workflow.
  • Custom Visuals: Design custom overlays or visual indicators that align with the user's interface for a cohesive look and feel.

Enhancing Clipboard Operations

To expand the clipboard functionality beyond text, integrate support for different data formats:

  • Image Data: Modify the C++ program to handle image data from the clipboard, enabling richer integrations.
  • Cross-Platform Support: Utilize libraries like Qt or wxWidgets to make the clipboard operations cross-platform, enhancing the program's versatility.

Securing Program Execution

Implement security measures to ensure that only trusted applications are executed:

  • Whitelist Executables: Restrict the programs that can be executed via gestures to a predefined whitelist.
  • Parameter Validation: Validate the clipboard content before passing it as a parameter to prevent malicious inputs.

Conclusion

By customizing StrokesPlus with Lua scripts and developing a dedicated C++ bridge program, you can significantly enhance the application's functionality. Displaying gesture action names improves user interaction, while integrating clipboard retrieval allows for dynamic execution of commands based on the latest clipboard content. This comprehensive approach not only streamlines workflows but also opens avenues for further customization and automation.

References


Last updated February 6, 2025

AI-assisted research. Sources, methodology and corrections · Source-checked guides and tools · Explore published answers

Ask Ithy AI