Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to have a script in AutoHotkey that allows me to do the following:

  • When I hit Control + Space: It would initiate "text selection mode" (i.e. if I move the cursor with the arrow keys, or moving the mouse it will highlight text)

  • When I hit Control + Space again: It would terminate "text selection mode" (e.g. if I move the cursor with the arrow keys or moving the mouse it will not highlight text)

However I would like to avoid using the following strategies, for the reasons explained below:

Strategy 1:

The following script does not let me move the cursor with the keyboard after I initiate text selection. Apparently the computer believes that I am constantly clicking on the mouse location, so it does not let me move the cursor with the keyboard.

*^Space::
text_selection_is_on := !text_selection_is_on
if text_selection_is_on
   Send, {Click down}
else
   Send, {Click up}
return

Strategy 2:

The following script relies on simulating the action of pressing the shift key down to initiate text selection. However, I would like to avoid relying on the shift key since some of the programs that I plan on using this script with require the shift key to be up (i.e. not pressed) when I move the cursor to select text.

*^Space::
text_selection_is_on := !text_selection_is_on
if text_selection_is_on
   Send, {Shift down}
else
   Send, {Shift up}
return

Is it possible to do this with AutoHotkey? If so, how?

Thanks!

share|improve this question
    
What is the definition of text_selection_is_on? –  ranomore May 3 '11 at 20:52
add comment

2 Answers

Very ugly but maybe it's the solution you were looking for. Very sad the shift down solution doesn't work for you, because that's what I've always been using.

*^Space::
dx = 1
dy = 1
text_selection_is_on := !text_selection_is_on
if text_selection_is_on
{
   MouseMove, %A_CaretX%, %A_CaretY%, 0
   dx := A_CaretX
   Send, {right}
   dx := A_CaretX - dx
   Send, {left}
   dy := A_CaretY
   Send, {down}
   dy := A_CaretY - dy
   Send, {up}
   Send, {Click down}
}
else
   Send, {Click up}
return

left::
if text_selection_is_on
    MouseMove, % -dx, 0, 0, R
else
   Send, {left}
return

right::
if text_selection_is_on
    MouseMove, % dx, 0, 0, R
else
   Send, {right}
return

down::
if text_selection_is_on
    MouseMove, 0, % dy, 0, R
else
   Send, {down}
return

up::
if text_selection_is_on
    MouseMove, 0, % -dy, 0, R
else
   Send, {up}
return
share|improve this answer
add comment

I do not think it is possible to select text without either dragging and holding down the mouse or using shift at all.

However, perhaps you could elaborate on these restrictions on using the shift key. Can the shift key not be used at all? Or can it be used as long it is held down for a very short time, and as long as the mouse and caret do not move during this time?

If that is the case, you could select the text as follows—that is, it works in my browser, and I think it works in most areas where you are able to select text by dragging the mouse; but I have no idea what program you plan to select text in.

  • Do a simple left-click on one end of the selection.
  • Move the mouse to the other end of the selection.
  • Do a shift + left-click there ( SendInput +{LButton} ).

Again, I have no idea as to the practical circumstances of your programs or the way their text selections work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.