Page 1 of 1

Keyboard shortcut to select all text in code block?

Posted: 09 Jun 2021, 19:43
by milkygirl90
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

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

Posted: 10 Jun 2021, 12:47
by aifritz
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...

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

Posted: 10 Jun 2021, 18:09
by reverberation
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.

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

Posted: 10 Jun 2021, 18:26
by AHKStudent
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

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

Posted: 10 Jun 2021, 21:20
by milkygirl90
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.

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

Posted: 12 Jun 2021, 13:13
by aifritz
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

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

Posted: 14 Jun 2021, 19:15
by milkygirl90
thanks! bumping it up.