Author Topic: Trying to get VA to make a word Capitalized or lowercase.  (Read 627 times)

iceblast

  • Sr. Member
  • ****
  • Posts: 374
Trying to get VA to make a word Capitalized or lowercase.
« on: May 04, 2024, 02:51:21 PM »
I was trying to use this command, but it doesn't seem like VA can recognize if there is Capital A or Lowercase a in the word.

Code: [Select]
Clear the Windows clipboard
Pause 0.2 seconds
Press Left Ctrl+Left Shift+Left keys and hold for 0.06 seconds and release
Press Left Ctrl+C keys and hold for 0.06 seconds and release
Set text [Correct] to '{CLIP}'
Begin Text Compare : [{TXT:Correct}] Does Not Contain 'A'
    Set text [Correct] to '{TXTTITLE:Correct}'
    Quick Input, '{TXT:Correct}'
    Clear the Windows clipboard
    Write [Blue] 'Capitalizing' to log
End Condition - Exit when condition met

If I run this command, it will Capitalize, doesn't matter what letter I Specify.


Since that's not going to work. Is there a way, where I can have one command, to check a word to see if it's Capitalized, or Lowercase, and switch it, and if the whole word is Capitalized, make it all lower.

It has to be a single press, and I can't hold the button for delay.

I'm using the Scrolllock as the key.


I've been trying to get this right for hours. Just to realize, VA isn't even telling the difference between letters. smh
« Last Edit: May 04, 2024, 04:21:45 PM by iceblast »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Trying to get VA to make a word Capitalized or lowercase.
« Reply #1 on: May 05, 2024, 01:42:57 AM »
Text comparisons are intentionally case-insensitive, like most of VoiceAttack is.


In theory, this could be solved using native features, as the "{TXTPOS:}" token (among others; it's just the most appropriate in this instance) performs a case-sensitive comparison:
Code: [Select]
Set text [~input] to '{CLIP}'
Begin Condition : [{TXTPOS:"A":~input:}] Does Not Equal '-1' OR [{TXTPOS:"B":~input:}] Does Not Equal '-1' OR [{TXTPOS:"C":~input:}] Does Not Equal '-1'
    Write [Blue] 'Input contains uppercase characters' to log
Else
    Write [Blue] 'Input does not contain uppercase characters' to log
End Condition
But then you'd only be checking for the specific characters in the comparison (and you'd need to add at least all 26 letters)


Using an inline function would likely be a more sensible option, E.G.
Code: [Select]
Set text [~input] to '{CLIP}'
Inline C# Function: Check input for uppercase characters, wait until execution finishes
Begin Boolean Compare : [~inputContainsUppercaseChars] Equals True
    Write [Blue] 'Input contains uppercase characters' displayed as [Square]
Else
    Write [Blue] 'Input does not contain uppercase characters' displayed as [Square]
End Condition
where "Check input for uppercase characters" contains
Code: [Select]
public class VAInline
{
public void main()
{
foreach (char c in VA.GetText("~input"))
{
if (char.IsUpper(c))
{
VA.SetBoolean("~inputContainsUppercaseChars", true);
return;
}
}
VA.SetBoolean("~inputContainsUppercaseChars", false);
}
}

The inline function handles all uppercase Unicode characters, rather than just the few you choose.

iceblast

  • Sr. Member
  • ****
  • Posts: 374
Re: Trying to get VA to make a word Capitalized or lowercase.
« Reply #2 on: May 05, 2024, 06:40:59 AM »
Awesome! It works perfectly!!!

Thanks, I've been doing this command very different for a few years now, but I had to change keys, and I only had 1 key as a option, and it just wouldn't work the same for some reason. Too many conflicts. That's why I needed it all to work with just a single press.

Now everything appears to be working just as I wanted!

Thanks again!

iceblast

  • Sr. Member
  • ****
  • Posts: 374
Re: Trying to get VA to make a word Capitalized or lowercase.
« Reply #3 on: May 05, 2024, 07:15:47 AM »
Have another issue.

This command was working, and now it doesn't.

Code: [Select]
Press Left Ctrl+Left Shift+Left keys and hold for 0.06 seconds and release
Press Left Ctrl+C keys and hold for 0.06 seconds and release
Set text [your] to '{CLIP}'
Write [Blue] '{CLIP}' to log
Begin Text Compare : [your] Equals 'your'
    Quick Input, 'you're'
End Condition - Exit when condition met

It would Recognize your, and change it to you're. Now, the compare statement is like it's not there. Just skips right over it. I don't understand. :( This command has worked for years.

SemlerPDX

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 291
  • Upstanding Lunatic
    • My AVCS Homepage
Re: Trying to get VA to make a word Capitalized or lowercase.
« Reply #4 on: May 05, 2024, 02:26:21 PM »
Have another issue.

This command was working, and now it doesn't.

Code: [Select]
Press Left Ctrl+Left Shift+Left keys and hold for 0.06 seconds and release
Press Left Ctrl+C keys and hold for 0.06 seconds and release
Set text [your] to '{CLIP}'
Write [Blue] '{CLIP}' to log
Begin Text Compare : [your] Equals 'your'
    Quick Input, 'you're'
End Condition - Exit when condition met

It would Recognize your, and change it to you're. Now, the compare statement is like it's not there. Just skips right over it. I don't understand. :( This command has worked for years.

You'll wanna copy your test output in the VA Event Log to clipboard, paste it somewhere you can examine each character, and see if you have some whitespace or something hindering your compare.

For example, I've copied your example actions and tested this with "your " (see whitespace after word, before endquote) and also with "your" ... the first was a failure but it is hard to see why simply looking at the entry in the Event Log here, and of course the second was a success but looks like the same output in the Event Log.


By copying this, I can paste it somewhere:



...such as Notepad++ where I can select the option to Show All Characters.  Here, I can see that there is a space between the "r" and the end of the line (CR-LF):



You can account for this by pre-processing the string in the clipboard, when you first set this "your" variable to that value like this:

*Note that "trim spaces" does NOT remove spaces in the value of this text variable, but only from before and/or after, from the beginning and/or the end.


Here you can select all sorts of other options, such as enforcing all upper/lower case, or even selective replacement directly inside the variable, if you wanted:


Best wishes and good luck!!

iceblast

  • Sr. Member
  • ****
  • Posts: 374
Re: Trying to get VA to make a word Capitalized or lowercase.
« Reply #5 on: May 05, 2024, 05:47:34 PM »
Yup, Trimming spaces did the trick.

The thing is, this command has been working for years, and I didn't change a thing, it just stop working.

I even manually looked for extra spaces, to make sure it was exactly the same, and still it didn't work, but hitting trim fixed it instantly. smh

Thanks for the help!