So I see StringUpper and StringLower to convert a string entirely to uppercase or lowercase, but that's not exactly what I want. My job requires me to use CapsLock a lot due to things that have to be written all in caps, and I often forget and write things that shouldn't be caps with capslock, or vice versa. What I am trying to make is a hotkey that takes the text I have selected, copies it, switches the case of each letter, and pastes it. So that, for example: "hI i AM bOB" becomes "Hi I am Bob".
Is there an easier way to do this than looking at the string letter by letter? (Alternatively, is there an easy way to loop through the string letter by letter?)
Uppersace/Lowersace Swap Script? Topic is solved
Re: Uppersace/Lowersace Swap Script?
Here are some ideas to get you started
https://autohotkey.com/board/topic/2443 ... -inverted/
https://autohotkey.com/board/topic/6312 ... e-options/
https://autohotkey.com/board/topic/2443 ... -inverted/
https://autohotkey.com/board/topic/6312 ... e-options/
- V for Vendetta
- Posts: 105
- Joined: 29 Sep 2016, 11:33
Re: Uppersace/Lowersace Swap Script? Topic is solved
try this:MaxAstro wrote:(Alternatively, is there an easy way to loop through the string letter by letter?)
Code: Select all
text = just a test
loop, parse, text
msgbox, %A_LoopField%
(Please, Mister Angry Great Admin "nnnik", approve this New Post of mine, please? Haha!)
ListView Control Editable - Cell Editing (Table - Grid - Spreadsheet)
VarWrite \ VarRead - A little bit faster alternative to IniWrite \ IniRead
ListView Control Editable - Cell Editing (Table - Grid - Spreadsheet)
VarWrite \ VarRead - A little bit faster alternative to IniWrite \ IniRead
More
Re: Uppersace/Lowersace Swap Script?
How would it know to capitalize "Bob" but not "am" ?
[Edit] Ah, I see, you need to toggle case. nvm
[Edit] Ah, I see, you need to toggle case. nvm
Last edited by evilC on 02 Dec 2016, 11:22, edited 1 time in total.
Re: Uppersace/Lowersace Swap Script?
http://lmgtfy.com/?q=ahk+toggle+caseMaxAstro wrote:What I am trying to make is a hotkey that .. switches the case of each letter
first result searches letter by letter and adds or subtracts 32 from the ASCII value
https://autohotkey.com/docs/commands/LoopParse.htmMaxAstro wrote: (is there an easy way to loop through the string letter by letter?)
second result shows a simple RegExReplace. this is probably easiest:MaxAstro wrote: Is there an easier way to do this than looking at the string letter by letter?
Code: Select all
string := "hI i AM bOB"
converted := RegExReplace(string, "([A-Z])|([a-z])", "$L1$U2")
MsgBox, %converted%
of course, Vim has the command g~ to toggle case, but i'm guessing you dont want to spend months learning a whole new text editorMaxAstro wrote: So that, for example: "hI i AM bOB" becomes "Hi I am Bob".
Re: Uppersace/Lowersace Swap Script?
Guest3456, thanks for the detailed set of options.
I think I'm gonna go with V's idea of using a parse loop, though - more readable than a RegEx.
Thanks everyone!
I think I'm gonna go with V's idea of using a parse loop, though - more readable than a RegEx.
Thanks everyone!
Re: Uppersace/Lowersace Swap Script?
thats a fine good idea. code is always read much more than it is written. so when it comes time to edit the script later, you want to be able to quickly understand whats going on. so i always support more readable code. if regex is difficult for you, stick with the loop.MaxAstro wrote: I think I'm gonna go with V's idea of using a parse loop, though - more readable than a RegEx.
Re: Uppersace/Lowersace Swap Script?
I've used a RegEx in exactly one place in my code, and I slightly regret it to this day - while it is by far the best way of doing what that bit of code needs to do, every time I scroll past it I think "what the heck does that do?" and it takes me a couple seconds to remember.
Re: Uppersace/Lowersace Swap Script?
Hrm. This is odd. So I set up a script that causes Shift + CapsLock to toggle the capslock state of the current selection, and it works fine. However, I would like Shift + CapsLock to also toggle capslock on or off. I tried two different ways of doing this, one by having the hotkey be ~+CAPSLOCK, and the other by adding Send {Capslock} at the end of the script. Both had the same result: if capslock was off, shift + capslock would turn it on. But if capslock is on, shift + capslock does not turn it off. Any idea why? Here is my script:
Code: Select all
+CAPSLOCK::
ClipSave := ClipboardAll
clipboard =
Send ^c
While clipboard =
{
Sleep, -1
}
Loop, parse, clipboard
{
if A_Loopfield is not alpha
TempVar1 := A_Loopfield
else if A_Loopfield is upper
StringLower, TempVar1, A_Loopfield
else if A_Loopfield is lower
StringUpper, TempVar1, A_Loopfield
Result .= TempVar1
}
Send % Result
clipboard := ClipSave
Result := ""
Send {CapsLock}
return
Re: Uppersace/Lowersace Swap Script?
see if using the $ modifier for the hotkey definition changes it
$+CAPSLOCK::
$+CAPSLOCK::
Re: Uppersace/Lowersace Swap Script?
Not sure if it's useful here... but a neat trick is that XOR'ing an ANSI A-Z character with the number 32 produces the lowercase character and vice-versa.
(It won't work for alpha characters that are not A-Z)
(It won't work for alpha characters that are not A-Z)
Code: Select all
Test := "abc123XYZ"
Loop, parse, Test
{
if A_Loopfield is not alpha
Result .= A_Loopfield
else
Result .= Chr(Asc(A_LoopField) ^ 0x20)
}
MsgBox, % Result
Re: Uppersace/Lowersace Swap Script?
$ modifier does not seem to help.
Another issue I am running into: curly braces disappear when this script is run. For example, "{hello}" gets changed to "HELLO". Not sure why this would be the case...
Another issue I am running into: curly braces disappear when this script is run. For example, "{hello}" gets changed to "HELLO". Not sure why this would be the case...
Re: Uppersace/Lowersace Swap Script?
see the help page for Send. curly braces have special meaning for that command. you'll probably need to escape them or use SendRawMaxAstro wrote:Another issue I am running into: curly braces disappear when this script is run. For example, "{hello}" gets changed to "HELLO". Not sure why this would be the case...
Who is online
Users browsing this forum: gongnl, mebelantikjaya, ThePeter and 241 guests