How to validate convert_to_UPPERCASE.ahk?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Stamimail
Posts: 77
Joined: 06 Nov 2014, 08:48

How to validate convert_to_UPPERCASE.ahk?

05 Jun 2020, 08:07

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
User avatar
boiler
Posts: 16951
Joined: 21 Dec 2014, 02:44

Re: How to validate convert_to_UPPERCASE.ahk?

05 Jun 2020, 08:45

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
}
ik4u
Posts: 80
Joined: 05 Jun 2020, 13:52
Contact:

Re: How to validate convert_to_UPPERCASE.ahk?

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
User avatar
boiler
Posts: 16951
Joined: 21 Dec 2014, 02:44

Re: How to validate convert_to_UPPERCASE.ahk?

05 Jun 2020, 14:59

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
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, ReyAHK and 463 guests