Keyboard shortcut to select all text in code block?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Keyboard shortcut to select all text in code block?

09 Jun 2021, 19:43

Not all Forums have a "select all" button in the Code block. For those that don't, is there a quick method I can use to easily copy/paste the entire block, instead of manually highlight start and end of the code block?

Code: Select all

this is a long block of code I want to copy 
xxx
xxx
xxx
aifritz
Posts: 301
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: Keyboard shortcut to select all text in code block?

10 Jun 2021, 12:47

To copy the code of the first post, this could be a simple approach.

You had to select the url in the browser before starting the hotkey

Code: Select all

^+c::
KeyWait c
KeyWait control
KeyWait shift

ClipBoard := ""
Send ^c
ClipWait 1

UrlDownloadToFile, % ClipBoard, % A_ScriptDir "\htmldata.txt"
If ErrorLevel
	{
		msgbox, There was an error... 
		exitapp
	}
	
FileRead, OutVar, % A_ScriptDir "\htmldata.txt"
OutScript := ""
Loop, parse, % OutVar, `n,`r
	{
		If InStr(A_LoopField, "<div class=""codebox""><p>Code")
			CopyYN := true, continue
		else if InStr(A_LoopField, "</Code")
			break
	    If CopyYN
	  	  OutScript .= A_LoopField "`n"
	}
Clipboard := OutScript
Filedelete % A_ScriptDir "\htmldata.txt"
msgbox Script copied to Clipboard

exitapp

Edit:
Ha, I just saw that the first row is missing... so you'll need a smarter way ...perhaps using regex or COM and innertext...
reverberation
Posts: 314
Joined: 13 Dec 2015, 20:48

Re: Keyboard shortcut to select all text in code block?

10 Jun 2021, 18:09

is it possible not to hard-code it? that is, wherever my mouse hovers over, that is the code block I want to copy-all.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Keyboard shortcut to select all text in code block?

10 Jun 2021, 18:26

milkygirl90 wrote:
09 Jun 2021, 19:43
Not all Forums have a "select all" button in the Code block. For those that don't, is there a quick method I can use to easily copy/paste the entire block, instead of manually highlight start and end of the code block?

Code: Select all

this is a long block of code I want to copy 
xxx
xxx
xxx
Use the shift key in chrome

Move your mouse to the first line you want to copy

Left click highlight first line or letter

Move to the last letter on the data you want to copy and click shift and hold down left mouse
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Keyboard shortcut to select all text in code block?

10 Jun 2021, 21:20

use the shift key in chrome

Move your mouse to the first line you want to copy

Left click highlight first line or letter

Move to the last letter on the data you want to copy and click shift and hold down left mouse
instead of manually highlight start and end of the code block?
that is exactly what I'm trying to avoid.
aifritz
Posts: 301
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: Keyboard shortcut to select all text in code block?

12 Jun 2021, 13:13

I've found some code from jeeswg which is able to grab the text under the mouse, but unfortunately the line breaks get lost.

Has someone an idea to solve this? Perhaps there is a way to execute the javascript function "this.select();"...??

https://www.autohotkey.com/boards/viewtopic.php?f=6&t=29458

Code: Select all


#IfWinActive, ahk_class IEFrame
q:: ;internet explorer - get element under cursor
;regardless of zoom percentage of 'Internet Explorer_Server' control
;it could potentially be incorporated into iWB2 Learner
IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"

CoordMode, Mouse, Screen
MouseGetPos, vMouseX, vMouseY,, hCtl, 3
WinGetClass, vCtlClass, % "ahk_id " hCtl
if !(vCtlClass == "Internet Explorer_Server")
	return
if !(oDoc := ComObject(9,ComObjQuery(Acc_ObjectFromWindow(hCtl),IID_IHTMLWindow2,IID_IHTMLWindow2),1).document)
	return
oWin := ComObject(9,ComObjQuery(oDoc,IID_IHTMLWindow2,IID_IHTMLWindow2),1)
oWB := ComObject(9,ComObjQuery(oWin,IID_IWebBrowserApp,IID_IWebBrowserApp),1)

vLogicalXDPI := oWB.document.parentWindow.screen.logicalXDPI
vDeviceXDPI := oWB.document.parentWindow.screen.deviceXDPI
vZoomRatio := vDeviceXDPI / vLogicalXDPI

;vWinX := oWin.screenLeft, vWinY := oWin.screenTop
;WinGetPos, vWinX2, vWinY2, vWinW2, vWinH2, ahk_class IEFrame
WinGetPos, vCtlX, vCtlY, vCtlW, vCtlH, ahk_id %hCtl%
vMouseX2 := (vMouseX-vCtlX)*(1/vZoomRatio)
vMouseY2 := (vMouseY-vCtlY)*(1/vZoomRatio)

oElt := oWin.document.elementFromPoint(vMouseX2, vMouseY2)
msgbox % oElt.Innertext
oDoc := oWin := oWB := oElt := ""
return
#IfWinActive

esc::exitapp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: haomingchen1998 and 245 guests