Moving selected text within line with hotkey

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Moving selected text within line with hotkey

27 May 2019, 03:57

Hi there,

In MS Word you are able to move paragraphs up and down by holding shift & alt and using the up and down arrows.
However, I would like to just move the selected word(s) left or right, like you are able to do in AHK Studio with the left & right arrow keys.
In AHK Studio this will move the selected text one space but I would like to move the selected text skipping whole words.

The actions that are needed for this are cut selected text -> press ctrl + left of right (so you skip a word) -> paste selected text.
I converted this to code but it doestn't work unfortunately. Both aren't doing what I want to.

Code: Select all

~^+!Right::
send {ctrl down}x
send {Right}
send v{ctrl up}
return

~^+!Right::
send {ctrl down}x{ctrl up}
send {ctrl down}{Right}{up}
send {ctrl down}v{ctrl up}
return
Any ideas?
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Moving selected text within line with hotkey

27 May 2019, 07:04

Just a starting point.

This works well on the first of the commented line at bottom ( left and right swapping) but will fails on the second line, due to the comma.
The selection MUST include a space after the desired word ( in this case I've selected the XXXXXX word followed by a space .

Code: Select all

#Persistent
~^+!Left::
send {ctrl down}x{ctrl up}
send {ctrl down}{Left}{up}
send {ctrl down}v{ctrl up}
send {ctrl down}{shift down}{left}{ctrl up}{shift up}
return

~^+!Right::
send {ctrl down}x{ctrl up}
send {ctrl down}{Right}{up}
send {ctrl down}v{ctrl up}
send {ctrl down}{shift down}{left}{ctrl up}{shift up}
return
ExitApp

esc::
  ExitApp
/*
XXXXXX Lorem ipsum dolor sit amet consectetur adipiscing elit Pellentesque rutrum massa nec massa aliquam 
XXXXXX Lorem ipsum dolor sit amet, consectetur adipiscing elit Pellentesque rutrum massa nec massa aliquam 
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: Moving selected text within line with hotkey

27 May 2019, 07:35

Hi, thanks for the reply!

Your solution doesn't work for me, I tested it in Notepad and it messed up my whole sentence. Could be that I did not explained it well enough...
I played a bit more with it myself and this is what I came up with. (Maybe try this in Notepad and you'll see what I'm trying to achieve here.)

Code: Select all

^+!Left::
send {ctrl down}x{ctrl up}
if (clipboard=""){
} else {
send {ctrl down}{Left}{ctrl up}
send % clipboard . A_Space
clipboard:=""
send {ctrl down}{shift down}{Left}{ctrl up}{shift up}
}
return

^+!Right::
send {ctrl down}x{ctrl up}
if (clipboard=""){
} else {
send {ctrl down}{Right}{ctrl up}
send % clipboard . A_Space
clipboard:=""
send {ctrl down}{shift down}{Right}{ctrl up}{shift up}
return
}
return
It does work in Notepad when moving a word just once, however, when I'm trying to move the word more than once it will dissapear...
In MS Word it does not works once. The selected text just gets completely removed when doing this in MS Word.
Why does that happen?
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Moving selected text within line with hotkey

27 May 2019, 08:39

I think the combo hotkey (control+shift+alt+right) does not work as expected in Notepad ( it works in Scite ).
Try this, It works for me in Notepad ( with the limitation exposed in my previous post) :

Code: Select all

#Left::
send {ctrl down}x{ctrl up}
send {ctrl down}{Left}{ctrl up}
send {ctrl down}v{ctrl up}
send {ctrl down}{shift down}{left}{ctrl up}{shift up}
return

#Right::
send {ctrl down}x{ctrl up}
send {ctrl down}{Right}{ctrl up}
send {ctrl down}v{ctrl up}
send {ctrl down}{shift down}{left}{ctrl up}{shift up}
return
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 178 guests