Hello
Just a quick one, how would I use +{Right} to keep going until it meets a certain character, for example a "/"?
Many thanks,
Ryan
Select text up to a certain character
Re: Select text up to a certain character
You could use the clipboard. Each time that you cursor right, copy the current selection to the clipboard and check whether the last character is a / or not.
I found that a sleep of 25 was the minimum needed on my system to ensure that the clipboard was updated. You may need to increase that a bit if you find that the cursor breaks past the / and continues on when you're holding down the keys.
Code: Select all
SendMode Input ; The following works a lot better with Send's Input mode
$+Right::
Send, {shift down}{right}{ctrl down}{c}{ctrl up}{shift up} ; Move the cursor right and copy the current selection to the clipboard
Sleep, 25 ; Give the system time to update the clipboard
StringRight, lastchar, clipboard, 1 ; Store the last character of the selection to variable lastchar
If lastchar = / ; If the last character is a /
Send, {shift down}{left}{ctrl down}{c}{ctrl up}{shift up} ; Move the cursor left (so that the / isn't included) and copy the current selection to the clipboard
Return
Re: Select text up to a certain character
That's brilliant, thanks Osprey
How would I go about making it automatically keep going right until it finds "/"?
Just now when I'm running it I need to keep pressing the assigned key for it to work.
How would I go about making it automatically keep going right until it finds "/"?
Just now when I'm running it I need to keep pressing the assigned key for it to work.
Re: Select text up to a certain character
If you mean that you want to release Shift and Right and have it continue selecting characters, a loop is required:
The references to "endloop" aren't necessary, but I figure that you might want some way to stop it, so I set Esc to do that.
Code: Select all
SendMode Input ; The following works a lot better with Send's Input mode
$+Right::
endloop := 0
Loop
{
Send, {shift down}{right}{ctrl down}{c}{ctrl up}{shift up} ; Move the cursor right and copy the current selection to the clipboard
Sleep, 25 ; Give the system time to update the clipboard
StringRight, lastchar, clipboard, 1 ; Store the last character of the selection to variable lastchar
}
Until endloop or lastchar = "/" ; End loop when last character = / (must be in quotes because it's an expression)
Send, {shift down}{left}{ctrl down}{c}{ctrl up}{shift up} ; Move the cursor left (so that the / isn't included) and copy the current selection to the clipboard
Return
~Esc::endloop := !endloop
-
- Posts: 1
- Joined: 27 May 2023, 12:41
Re: Select text up to a certain character
I knot whis topic is quide old but it saved my life today, however, I was wondering if this operation could be sped up. I modified the script to select whole words but I cannot figure out how to make AHK check if my specific character is contained anywhere in clipboard and then revert selection back by one word. What I wanted to achieve is the following sequence: Select first word, check if clipboard contains my character (/ in the example above). If not, repeat to select another word and copy two words to clipboard, then check if it contains the character and so on until it finds this character in clipboard. If it does it should move selection one word back. Selection sequences are clear to me but I cannot make it look for specific character in clipboard content. I will be extremely grateful for your help.