How to instantly duplicate the current line (i.e. make a copy of current line & paste in next line) M S Word and Notepad Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

How to instantly duplicate the current line (i.e. make a copy of current line & paste in next line) M S Word and Notepad

09 Jun 2019, 03:55

Hello Friends..


As we can instantly duplicate the current line in Scite and AHK Studio with the help me shortcut keys like ctrl+D and f2 respectively, I want any similar way to duplicate the current line for MS Word and notepad. Presently, I have mapped the default keys to duplicate the current line. Please see these codes-

Code: Select all

send {Home}  ; brings the cursor to the starting of the line
Sleep 100
send +{End}  ; selects the entire line
Sleep 100
send ^c  ; copies the text
Sleep 100
send {down}  ; goes to the next line
Sleep 100
send ^v     ; pastes the text at next line

However, the above codes are working fine, but I want more professional way to do that. Like in scite it provides the facility to duplicate the current line by shortcut key ctrl+d and in AHK studio it has built in shortcut key f2.

Please tell me how to do this in MS Word and in Notepad?


Thanks a lot...
I don't normally code as I don't code normally.
User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

Re: How to instantly duplicate the current line (i.e. make a copy of current line & paste in next line) M S Word and Not

09 Jun 2019, 04:34

Code: Select all

#SingleInstance force
#Persistent

^+d::  ; Duplicate
	send {Home}  ; brings the cursor to the starting of the line
	Sleep 10
	send +{End}  ; selects the entire line
	Sleep 10
	send ^c  ; copies the text
	Sleep 10
	send {End}  ; goes to the end of line
	Sleep 10
	send {Enter}  ; creates a new line
	Sleep 10
	send ^v     ; pastes the text at next line
	return
	
But this one duplicates a line but not a paragraphe.
(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »
pureby
Posts: 8
Joined: 08 Jun 2019, 14:07

Re: How to instantly duplicate the current line (i.e. make a copy of current line & paste in next line) M S Word and Not

09 Jun 2019, 09:42

Sabestian Caine wrote:
09 Jun 2019, 03:55
the above codes are working fine, but I want more professional way to do that. Like in scite it provides the facility to duplicate the current line by shortcut key ctrl+d and in AHK studio it has built in shortcut key f2.

Please tell me how to do this in MS Word and in Notepad?
The script you posted seems to do exactly what you want in the most efficient way. So what do you mean by "more professional way"? If you want the script to only work in Notepad (not in other apps), then you should add the following lines to the end and beginning of your script:

Code: Select all

	#IfWinActive ahk_exe C:\Windows\System32\notepad.exe
		YOUR_SCRIPT_HERE
	#IfWinActive

I hope this helps. Otherwise, please explain better what it is exactly that you want to achieve?
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to instantly duplicate the current line (i.e. make a copy of current line & paste in next line) M S Word and Not

09 Jun 2019, 11:55

pureby wrote:
09 Jun 2019, 09:42
Sabestian Caine wrote:
09 Jun 2019, 03:55
the above codes are working fine, but I want more professional way to do that. Like in scite it provides the facility to duplicate the current line by shortcut key ctrl+d and in AHK studio it has built in shortcut key f2.

Please tell me how to do this in MS Word and in Notepad?
The script you posted seems to do exactly what you want in the most efficient way. So what do you mean by "more professional way"? If you want the script to only work in Notepad (not in other apps), then you should add the following lines to the end and beginning of your script:

Code: Select all

	#IfWinActive ahk_exe C:\Windows\System32\notepad.exe
		YOUR_SCRIPT_HERE
	#IfWinActive

I hope this helps. Otherwise, please explain better what it is exactly that you want to achieve?


Hello dear pureby...

My codes are just the mapping of inbuilt shortcut keys. They are not instantly duplicating the line and thus not showing more professional approach.

You can understand it by simple example-
Suppose, you want to insert text in some edit field then there are numerous ways to do this in autohotkey. One way is to just put your cursor in that edit field then use sendinput, some text . Second way is to use ControlSetText command which works more efficiently and professionally. I have the same concern with above codes. I hope you have understood what I mean..

Secondly, Please look at this gif-
ram4.gif
ram4.gif (43.65 KiB) Viewed 2430 times

in the above clip you can clearly see that how instantly we can duplicate current line Scite. I want such kind of thing. I know this can be by Autohotkey, but how? don't know..

Thanks a lot..
I don't normally code as I don't code normally.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to instantly duplicate the current line (i.e. make a copy of current line & paste in next line) M S Word and Not

09 Jun 2019, 12:07

I've been using the following:

Code: Select all

#IfWinActive ahk_class Notepad
^d:: ;notepad - send text - duplicate line
ControlGet, hCtl, Hwnd,, Edit1, A
ControlGet, vLineNum, CurrentLine,,, % "ahk_id " hCtl
ControlGet, vText, Line, % vLineNum-1,, % "ahk_id " hCtl
Control, EditPaste, % vText,, % "ahk_id " hCtl
return
#IfWinActive

#IfWinActive ahk_class OpusApp ;word
^d:: ;word - send text - duplicate line
SendInput, {Up}{Home}+{End}
oWd := ComObjActive("Word.Application")
vText := RTrim(oWd.Selection.Text, "`r`n")
SendInput, {Down}{End}
oWd.Selection.TypeText(vText)
oWd := ""
return
#IfWinActive
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: How to instantly duplicate the current line (i.e. make a copy of current line & paste in next line) M S Word and Not  Topic is solved

09 Jun 2019, 12:15

At the moment I got only an old Word 2003 to test it but this works in this version

Code: Select all

f8::
   oWord := ComObjActive("Word.Application")
   selection := oWord.selection
   Selection.HomeKey(wdLine:=5)
   Selection.EndKey(wdLine, wdExtend:=1)
   currentline := Selection.Range
   Selection.HomeKey(wdLine)
   Selection.TypeText(currentline.text)
return
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to instantly duplicate the current line (i.e. make a copy of current line & paste in next line) M S Word and Not

09 Jun 2019, 13:24

jeeswg wrote:
09 Jun 2019, 12:07
I've been using the following:

Code: Select all

#IfWinActive ahk_class Notepad
^d:: ;notepad - send text - duplicate line
ControlGet, hCtl, Hwnd,, Edit1, A
ControlGet, vLineNum, CurrentLine,,, % "ahk_id " hCtl
ControlGet, vText, Line, % vLineNum-1,, % "ahk_id " hCtl
Control, EditPaste, % vText,, % "ahk_id " hCtl
return
#IfWinActive

#IfWinActive ahk_class OpusApp ;word
^d:: ;word - send text - duplicate line
SendInput, {Up}{Home}+{End}
oWd := ComObjActive("Word.Application")
vText := RTrim(oWd.Selection.Text, "`r`n")
SendInput, {Down}{End}
oWd.Selection.TypeText(vText)
oWd := ""
return
#IfWinActive

Thanks dear jeeswg... Your codes are working almost excellent, however the codes for notepad are not working desired.... Thanks a lot sir...
I don't normally code as I don't code normally.
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to instantly duplicate the current line (i.e. make a copy of current line & paste in next line) M S Word and Not

09 Jun 2019, 13:25

Odlanir wrote:
09 Jun 2019, 12:15
At the moment I got only an old Word 2003 to test it but this works in this version

Code: Select all

f8::
   oWord := ComObjActive("Word.Application")
   selection := oWord.selection
   Selection.HomeKey(wdLine:=5)
   Selection.EndKey(wdLine, wdExtend:=1)
   currentline := Selection.Range
   Selection.HomeKey(wdLine)
   Selection.TypeText(currentline.text)
return

Thank you so much dear Odlanir... these codes for ms word are working great without any issue... Thank you sir... :bravo:
I don't normally code as I don't code normally.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5 and 255 guests