Page 1 of 1

How to validate convert_to_UPPERCASE.ahk?

Posted: 05 Jun 2020, 08:07
by Stamimail
Here is the script:

Code: Select all

sendinput, ^c
tempvar := clipboard
stringupper, tempvar, tempvar
clipboard := tempvar
sleep, 100
sendinput, ^v
I need it to run only when text is selected.
I need to ensure that in any other case I run this script by mistake (like when file is selected) it will DO NOTHING

Re: How to validate convert_to_UPPERCASE.ahk?

Posted: 05 Jun 2020, 08:45
by boiler
This will check that there is at least one lowercase letter to be converted to uppercase. It also uses ClipWait to make sure not to continue until the clipboard is loaded with text.

Code: Select all

clipboard := ""
sendinput, ^c
ClipWait, 1
tempvar := clipboard
if (!ErrorLevel && RegExMatch(tempvar, "[a-z]")) {
	stringupper, tempvar, tempvar
	clipboard := tempvar
	sleep, 100
	sendinput, ^v
}

Re: How to validate convert_to_UPPERCASE.ahk?

Posted: 05 Jun 2020, 14:25
by ik4u
I need help with this:
1) text in clipboard
2) 1st 2 characters (max 3 characters) convert alphabet to number (A=1, B=2 C=3.....Z=26), and number to alphabet (1=A, 2=B, 3=C....26=Z)
3) convert word (any word) uppercase to lower and lower to uppercase ( D5 SmILE = 4E sMile , 15B crAZY = O2 CRazy , Z12 TONIGHT = 26L tonight)
4) once converted will be entered at the macro recorded location

thanks

Re: How to validate convert_to_UPPERCASE.ahk?

Posted: 05 Jun 2020, 14:59
by boiler
ik4u wrote:
05 Jun 2020, 14:25
I need help with this:
1) text in clipboard
2) 1st 2 characters (max 3 characters) convert alphabet to number (A=1, B=2 C=3.....Z=26), and number to alphabet (1=A, 2=B, 3=C....26=Z)
3) convert word (any word) uppercase to lower and lower to uppercase ( D5 SmILE = 4E sMile , 15B crAZY = O2 CRazy , Z12 TONIGHT = 26L tonight)
4) once converted will be entered at the macro recorded location

thanks
Generally, you should create a new thread for a new topic, but I'll answer this. The script below takes what's in the clipboard and puts the converted string back into the clipboard:

Code: Select all

RegExMatch(Clipboard, "([a-zA-Z]+|\d+)([a-zA-Z]+|\d+) ([a-zA-Z]+)", M)
Clipboard := AlphaNumSwap(M1) . AlphaNumSwap(M2) . " " . UpperLowerSwap(M3)
return

AlphaNumSwap(s) {
	if s is number
		return Chr(s + 64)
	else
		return Ord(s) - 64
}

UpperLowerSwap(s) {
	loop, % StrLen(s) {
		t := SubStr(s, A_Index, 1)
		if t is upper
			StringLower, t, t
		else
			StringUpper, t, t
		u .= t
	}
	return u
}