Selecting Words With the Mouse in SDL Trados Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Selecting Words With the Mouse in SDL Trados

22 Jul 2021, 11:25

In Microsoft Word, multiple whole words can be selected by double-clicking on a word to select it and then dragging the mouse to continue adding whole words to the selection.

In the translation software SDL Trados, the first part (i.e. double-clicking to select a word) works, but words are not added to the selection when the cursor is then dragged over the rest of the words. To select multiple whole words, the user has to press Ctrl + Shift + Right / Left, increasing the selection word by word by pressing an arrow key.

Because SDL Trados has this limitation, I am trying to create a script to select multiple words with the mouse in this software. The following are the suggested steps:

1) When the user makes a left click, send a click again (in order to select a whole word).
2) While the user continues holding the left mouse button and moves the cursor to the left or right by at least 50 pixels, send {LCtrl Down}{LShift Down}{Left / Right}{LShift Up}{LCtrl Up} to select the next word (in the direction in which the user has moved the cursor by at least 50 pixels).
3) If the user further moves the cursor 50 pixels either to the left or right, repeat step 2 above.

I have been able to write only the first part of the script, because I do not know how to write the commands which have to do with counting pixels when the cursor is moved:

Code: Select all

#IfWinExist ahk_exe SDLTradosStudio.exe
~LButton::
Click, Left, , Up 
click 1 ; send an additional click to select a whole word
return ; I am not sure whether the Return command is to be put here or in another place

 … … …   ; this is where the commands for detecting mouse moves and counting pixels are to be written
#IfWinExist
Does anyone know how to write the remaining commands?
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Selecting Words With the Mouse in SDL Trados  Topic is solved

22 Jul 2021, 11:31

You could use SetTimer to MouseGetPos, and then identify the distance traveled.

An alternative could just be using a key such as F3 to select both the first word and subsequent words.
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Selecting Words With the Mouse in SDL Trados

23 Jul 2021, 09:18

mikeyww wrote:
22 Jul 2021, 11:31
You could use SetTimer to MouseGetPos, and then identify the distance traveled.

An alternative could just be using a key such as F3 to select both the first word and subsequent words.
Thank you. The SetTimer command seems to be a standard way to run a continuous thread within a script to carry out a certain action.
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Selecting Words With the Mouse in SDL Trados

23 Jul 2021, 13:31

I have tried the following script, but words are not added to a current selection when I move the cursor to the left or right by more than 50 pixels while continuing to hold LButton.

For easier testing, I have replaced the Send commands with SoundBeep to detect whether the script works as intended. When the cursor is moved to the left by more than 50 pixels from the previous position, SoundBeep 1000 should be triggered, whereas if the cursor is moved to the right by more than 50 pixels from the previous position, SoundBeep 2000 should be triggered.

I have specified ahk_exe notepad.exe instead of ahk_exe SDLTradosStudio.exe to make it easier to test the script.

What should be changed in the script so that it may work?

Code: Select all

#IfWinActive, ahk_exe notepad.exe
~LButton::
Click, Left, , Up
click 1 ; send an additional click to select a whole word automatically
MouseGetPos x1, y1
if getkeystate(LButton, "P")
SetTimer, CursorPosition, 50
return
#IfWinActive

CursorPosition:
MouseGetPos x2, y2
if x2-x1>-50
{
soundbeep 1000
;~ send {LCtrl Down}{LShift Down}
;~ Send {Left}{LShift up}{LCtrl Up}
}
else if x2-x1>50
{
soundbeep 2000
;~ send {LCtrl Down}{LShift Down}
;~ Send {Right}{LShift up}{LCtrl Up}
}
else SetTimer, CursorPosition, OFF
return
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Selecting Words With the Mouse in SDL Trados

23 Jul 2021, 13:51

Your ">" should probably be "<". A demo is below.

Code: Select all

F3::
MouseGetPos, x1, y1
SoundBeep, 1500
SetTimer, Check, 250
Return

Check:
MouseGetPos, x2, y2
If Abs(x2 - x1) < 50
 Return
SetTimer,, Off
SoundBeep, 1000 + 1000 * (x2 > x1)
Gosub, F3
Return
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Selecting Words With the Mouse in SDL Trados

24 Jul 2021, 11:49

Thank you for the script, which gives an idea of how a checking operation can be performed at intervals. I was not aware of the existence of the Abs mathematical function, which is useful in this instance.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750, septrinus and 251 guests