2

I made this simple script that allows me to have multiple clipboards. By selecting some text and pressing Win+1, the text is copied in Clipboard1. If I don't have text selected, the contents of the clipboard are pasted. The same for Win+2 and 3.

It works, but I have two minor issues I'd like to solve.

First, the code:

copiesOrNot()
{
    tempClip1Test1 = %Clipboard%
    Send ^c
    tempClip1Test2 = %Clipboard%
    if (tempClip1Test1 = tempClip1Test2)
        return false
        else
        return true
}


#1::
    if copiesOrNot()
            clipText1 = %Clipboard%
        else
            SendRaw %clipText1%
    Return

#2::
    if copiesOrNot()
            clipText2 = %Clipboard%
        else
            SendRaw %clipText2%
    Return

#3::
    if copiesOrNot()
            clipText3 = %Clipboard%
        else
            SendRaw %clipText3%
    Return

My questions:

1) In Chrome (and some other browsers), there is an annoying beep sound whenever a Copy command is sent and no text is selected. Since this is used in my code (in the function copiesOrNot), I get the beep when I use the script in Chrome.

I'm not against having the beep when I manually try to copy without text selected, but I'd like to bypass that warning in the context of my script. Is it possible?

Or could anyone suggest another way of checking if there is text selected ? I do it by sending a Copy command and checking if there was any change in the Clipboard, which I realize is not a very good solution, though it works (the thing is, in Windows, whenever you try to Copy without text selected, the Clipboard is not emptied - it just keeps the current content).

(I did find some alternatives for checking if there is text selected, but they are very complex, or require additional libraries. I'd rather keep thinks simple)

2) I'd like to not have to repeat the code for each number (Win+1, Win+2 etc.) Is there a way of doing that? For example: have the script activate when the user presses Win+ANY-NUMBER, then in the code get the actual number value and use it to create dynamically named variables?

Thanks!

PS: let me know if this is confusing (my english is not very good) or if I posted in the wrong place (It's my first post in StackOverflow)

0 Answers0