sabrogden / Ditto

Ditto is an extension to the Windows Clipboard. You copy something to the Clipboard and Ditto takes what you copied and stores it in a database to retrieve at a later time.
https://ditto-cp.sourceforge.io/
3.95k stars 208 forks source link

Feature request : suggested On Paste Scripts : Paste as simulated keypressed to focused window #612

Open shodanx2 opened 10 months ago

shodanx2 commented 10 months ago

Sometimes you have situations where you cannot paste

I would like to special paste "paste as simulated key pressed"

Where the script would simulate keypress for all of the clip's text content

Here is a non functional placeholder script

// Assume 'clip.Text' holds the text you want to "paste" via simulated keypresses
var textToPaste = clip.Text;

// Function to simulate a keypress for each character in the string
function simulateKeypress(character) {
    // This is a placeholder function. You'll need to replace this with actual keypress simulation code
    // specific to your environment or scripting language.
    console.log("Simulating keypress for: " + character);
}

// Loop through each character in the text to paste
for (var i = 0; i < textToPaste.length; i++) {
    simulateKeypress(textToPaste[i]);
}

return false; // Prevent the default paste action since we're simulating keypresses

Alternate version

// Get the text from the clipboard
var textToPaste = clip.Text;

// Construct the command to run the AutoHotkey script with the text as an argument
// Make sure to properly escape the textToPaste if it contains spaces or special characters
var command = 'AutoHotkey.exe YourScript.ahk "' + textToPaste + '"';

// Execute the command
// This is a placeholder function. You'll need to replace this with the actual code to execute a command in Ditto
executeCommand(command);

function executeCommand(cmd) {
    // Placeholder for executing an external command in Ditto
    // The actual implementation depends on Ditto's capabilities and might involve calling an external shell or command processor
    console.log("Executing command: " + cmd);
}

return false; // Prevent the default paste action

And that would require calling AutoHK for doing the actual keypresses

; Check if at least one argument is provided
if (0 < A_Args.Length()) {
    textToPaste := A_Args[1]  ; Use the first argument as the text to paste

    ; Loop through each character in the string
    Loop, Parse, textToPaste
    {
        SendInput, %A_LoopField%
        Sleep, 50  ; Brief pause between keystrokes
    }
} else {
    MsgBox, No text provided to paste.
}
shodanx2 commented 9 months ago

To make this work

I can see two approaches, using autohk write a special made autohk script using the clip, to file then run autohk to that file

So, looking at the chaiscript documentation

https://github.com/ChaiScript/ChaiScript/blob/develop/cheatsheet.md

https://codedocs.xyz/ChaiScript/ChaiScript/annotated.html

I can't seem to find how to

Use chaiscript to write to a file

Use chaiscript to run a program

another approach, ditto might be able to simulate keypress directly ?

https://github.com/sabrogden/Ditto/wiki/Custom-Key-Strokes