StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
dwStrokes  
#1 Posted : Wednesday, October 28, 2020 8:15:53 AM(UTC)
dwStrokes

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/27/2020(UTC)
Posts: 2
South Africa

Hi, is there a way to cycle through upper, lower and sentence case in SP? I'd like to be able to select text and be able to change case either through a gesture or a hot key BigGrin
Rob  
#2 Posted : Wednesday, October 28, 2020 2:27:34 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
This will kind of work, but it's not ideal since S+ can only use the clipboard and send key functions to accomplish this.

Applications which have that function built-in will always work much more smooth/fast than an external program interacting via clipboard/keys - but, you can see what you think.

Note that "sentence case" is a little challenging to apply due to variances in how the selected text is structured. For example, you would have to apply a lot of grammatical logic to do this properly, and that's a bit much to do. You can probably find JavaScript out there which may handle this and you can update accordingly. I chose to use Title Case instead as that is very simple.

Code:
//Note that if you do not have text selected and there is text on the 
//clipboard, that text will be used

//Copy the selection to the clipboard (Ctrl+C)
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]);
sp.Sleep(50);

//Get the selected text from the clipboard
var selText = clip.GetText();

//If there is a valid value returned from the clipboard
if(selText != null && selText.length > 0)
{
    var lowerCase = selText.toLowerCase();
    var upperCase = selText.toUpperCase();
    var titleCase = selText.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});

    if(selText !== lowerCase && selText !== upperCase)
    {
        //If the selection is neither all upper or lower case, put lower case on clipboard
        clip.SetText(lowerCase);
    }
    else if(selText === lowerCase)
    {
        //If the selection is all lower case, put upper case on clipboard
        clip.SetText(upperCase);
    }
    else if(selText === upperCase)
    {
        //If the selection is all upper case, put title case on clipboard
        clip.SetText(titleCase)
    }

    //Slight pause then paste clipboard (Ctrl+V)
    sp.Sleep(50);
    sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_V]);
    sp.Sleep(25);

    //Send the Shift key down
    sp.SendShiftDown();
    //For each character, send the Left arrow key, to re-select the text
    for(var i = 0; i < selText.length; i++)
    {
        sp.SendVKey(vk.LEFT);
    }
    //Release the Shift key
    sp.SendShiftUp();
}

Edited by user Wednesday, October 28, 2020 2:29:01 PM(UTC)  | Reason: Not specified

dwStrokes  
#3 Posted : Wednesday, October 28, 2020 3:24:12 PM(UTC)
dwStrokes

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/27/2020(UTC)
Posts: 2
South Africa

Thanks Rob, but I get some syntax errors when running the script. This isn't a major requirement, so no worries if you don't have time to spend on it right now ;)
Rob  
#4 Posted : Wednesday, October 28, 2020 3:59:00 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
What errors? It worked fine when I tested it.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.