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.78k stars 197 forks source link

Feature Rq : Special paste to actually type out clipboard instead of pasting (for when pasting doesn't work) #419

Open shodanx2 opened 1 year ago

shodanx2 commented 1 year ago

Hello,

Just found another potential usage for Ditto special paste

You know sometimes there is a window that you can paste into ? For some reason, pasting is disabled

Sometimes it's an overzealous two factor prompt or password field

Or here is the example I'm struggling with

I have ubuntu running in a VM, in proxmox and visible through noVNC.

I can type in this window but for some obscure reason that I don't have the time to investigate, copy and paste to that, does not work.

If I could have "special pasted" as keystrokes my command, that would have saved me some grief here !

Screenshot !

image

EdEastman commented 1 year ago

I've worked around this with AutoHotKey but it'd be cool to have it as part of ditto

kp-gl commented 1 year ago

+1 Ditto is cool, but I also miss "Put into clipboard" instead of paste

shodanx2 commented 1 year ago

kp-gl, if you press ctrl+c on a clip, it will put it into the clipboard


I'm here today because again there was a textbox that was not letting me paste, it would have been great to use ditto to type out my clip as a series of keypresses !

Chealer commented 9 months ago

This must be a duplicate of ticket #100 .

shodanx2 commented 8 months ago

I have created a preliminary On Paste script.

It does not yet work, I'm not sure why

This script will create an autohk script and put that script in your clipboard

Then you have to change the window title, save it as a file with .ahk extension and run it, while having autohk installed

Ideally, Ditto, would write the output to a file, ask the user for the partial window title and then run this file using autohk after checking that it is installed.

That will help a LOT of people, especially virtual machine users. But anywhere that you can paste easily.

// Function to escape AHK special characters in a line of text
def escapeAHKSpecialChars(line) {
    // Implement the necessary escapes for AHK syntax here
    line = line.replace("{", "{{}");
    line = line.replace("}", "{}}");
    // Add more replacements as needed for AHK
    return line;
}

// Initialize the AHK script with the setup commands
var ahkScript = "SetTitleMatchMode, 2\n\n";
ahkScript += "IfWinExist, WRITE THE NAME OF YOUR WINDOW HERE\n";
ahkScript += "{\n    WinActivate\n    Sleep, 500\n\n";

// Get the entire clipboard content
var allText = clip.GetAsciiString();
var start = 0;

// Manually iterate over each line in allText
for (var i = 0; i <= allText.size(); ++i) {
    if (i == allText.size() || allText[i] == '\n') {
        // Extract the current line
        var line = allText.substr(start, i - start);

        // Escape special characters for AHK and format the line for SendRaw command
        var escapedLine = escapeAHKSpecialChars(line);
        ahkScript += "    SendRaw, " + escapedLine + "{Enter}`n";

        // Prepare for the next line
        start = i + 1;
    }
}

// Finalize the AHK script
ahkScript += "    ExitApp  ; Exits the script\n}\n";
ahkScript += "else\n{\n    MsgBox, The specified window was not found.\n    ExitApp  ; Exits the script if the window is not found\n}\n";

// Output the AHK script for the user
print(ahkScript);

return false;  // Prevent the original text from being pasted

This script, outputs the input directly, not sure why. It is based on the MAC conversion on paste scripts.

It needs to ask the user for the window title, or get window title of the focused window

Output to a file

run file using autohk

warn user if autohk is not installed

shodanx2 commented 8 months ago

Also, some text in the clip will need to be escaped per

https://www.autohotkey.com/docs/v1/lib/Send.htm

[Raw mode](https://www.autohotkey.com/docs/v1/lib/Send.htm#Raw)

The Raw mode can be either enabled with {Raw}, SendRaw or [ControlSendRaw](https://www.autohotkey.com/docs/v1/lib/ControlSend.htm), which causes all subsequent characters, including the special characters ^+!#{}, to be interpreted literally rather than translating {Enter} to Enter, ^c to Ctrl+C, etc. For example, both [Send](https://www.autohotkey.com/docs/v1/lib/Send.htm) {Raw}{Tab} and [SendRaw](https://www.autohotkey.com/docs/v1/lib/Send.htm) {Tab} send {Tab} instead of Tab.

The Raw mode does not affect the interpretation of [escape sequences](https://www.autohotkey.com/docs/v1/misc/EscapeChar.htm), [variable references](https://www.autohotkey.com/docs/v1/Variables.htm#retrieving) and [expressions](https://www.autohotkey.com/docs/v1/Variables.htm#Expressions). For example, [SendRaw](https://www.autohotkey.com/docs/v1/lib/Send.htm) ``100`% sends the string `100%. When using [ControlSend](https://www.autohotkey.com/docs/v1/lib/ControlSend.htm), it is also necessary to escape literal commas (`,).

https://www.autohotkey.com/docs/v1/misc/EscapeChar.htm

![image](https://github.com/sabrogden/Ditto/assets/10621885/c3a4dfbf-4232-4e95-ba3c-8361968d236f)