Quicker way to open script file for editing

Get help with using AutoHotkey and its commands and hotkeys
nathan323
Posts: 41
Joined: 31 Jan 2016, 02:53

Quicker way to open script file for editing

08 Jan 2017, 09:08

Howdy all.

I'm aware that you can hit Context+E, or right-click and Edit. What would be faster would be say holding Ctrl+Shft and double-clicking file. A good precedence for this is how you can hold Alt and double-click a file to shortcut straight to the Properties dialog. Or holding Ctrl+Shft and double-clicking a folder to open in a new window.

This would obviously go for other language files like BAT, VBS, REG files, etc.

I'm thinking that Alt/Properties thing must be in the registry somewhere, but (a) I have no idea where yet :?: , and (b) thought I would throw down the possibility of an AHK script to achieve this?
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Quicker way to open script file for editing

08 Jan 2017, 11:30

I liked this idea and thought I'd try and program it, using Shift+Enter as a hotkey, for the Desktop and for folder windows.

[EDIT:] New version:

Code: Select all

#IfWinActive ahk_class CabinetWClass
+Enter:: ;open file with Paint/Notepad (open folder in new window)
#IfWinActive ahk_class ExploreWClass
+Enter::
#IfWinActive ahk_class Progman
+Enter::
#IfWinActive ahk_class WorkerW
+Enter::
WinGet, hWnd, ID, A
WinGetClass, vWinClass, % "ahk_id " hWnd
vPath := "", vIsDir := 0

if (vWinClass = "CabinetWClass") || (vWinClass = "ExploreWClass")
{
	for oWin in ComObjCreate("Shell.Application").Windows
	{
		if (oWin.HWND = hWnd)
		{
			vIsDir := oWin.Document.FocusedItem.IsFolder
			vPath := oWin.Document.FocusedItem.Path
			break
		}
	}
	oWin := ""
}
else if (vWinClass = "Progman") || (vWinClass = "WorkerW")
{
	VarSetCapacity(hWnd, 4, 0)
	;SWC_DESKTOP := 0x8 ;VT_BYREF := 0x4000 ;VT_I4 := 0x3 ;SWFO_NEEDDISPATCH := 0x1
	oWin := ComObjCreate("Shell.Application").Windows.FindWindowSW(0, "", 8, ComObject(0x4003, &hWnd), 1)
	vIsDir := oWin.Document.FocusedItem.IsFolder
	vPath := oWin.Document.FocusedItem.Path
	oWin := ""
}

if (vPath = "")
{
	MsgBox, % "error: file not found"
	return
}
else if !FileExist(vPath)
{
	MsgBox, % "error: file not found:`r`n" vPath
	return
}
else if vIsDir
{
	Run, % Chr(34) vPath Chr(34)
	return
}
FileGetSize, vSizeMB, % vPath, M
if (vSizeMB > 6)
{
	MsgBox, % "error: file too big: " vSizeMB " MB"
	return
}
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
if vExt in % "bmp,gif,jpe,jpeg,jpg,png"
	Run, mspaint.exe "%vPath%"
else
	Run, notepad.exe "%vPath%"
return
Old version:
Spoiler
Last edited by jeeswg on 10 May 2019, 10:14, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
nathan323
Posts: 41
Joined: 31 Jan 2016, 02:53

Re: Quicker way to open script file for editing

08 Jan 2017, 21:04

Excellent work mate :)
I'm using Ctrl+Enter/NumpadEnter so I've changed hotkeys accordingly.
I'm going to play around with it to try to get Ctrl+double-click to work.
And also a lot of the time I am editing code files, I'm using shortcuts (I noticed "lnk" in your included file extensions). When I use your script on shortcuts though, it gives me an edit of the shortcut file itself - normal behaviour. I'm going to play around with an Else down there just for "lnk" files, try and get the true path then edit that.

I'm going to try and do all this before checking this page again in the interest of learning for myself ;) But it might take me a while hah. Saw you're online though so thought I'd jump in and say thanks!
nathan323
Posts: 41
Joined: 31 Jan 2016, 02:53

Re: Quicker way to open script file for editing

09 Jan 2017, 00:18

Code: Select all

if vExt in ,bat,ahk,reg,vbs,txt,htm,html,mht,cpp,h,m3u,mpcpl,url,clp,ini,cfg,csv,srt,log
Run, "notepad.exe" "%vPath%"
else if vExt in bmp,gif,jpe,jpeg,jpg,png
Run, "mspaint.exe" "%vPath%"
else if vExt in ,lnk
{FileGetShortcut, %vPath%, OutTarget
Run, "notepad.exe" "%OutTarget%"
}
Return
This works to edit target files from a shortcut.
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Quicker way to open script file for editing

09 Jan 2017, 01:13

Cheers! I virtually never use lnk files, I press win+f, which opens up a menu, I type in a shorthand and press enter.
I didn't really think of links being to text files, only the start menu links, which if you opened them in Notepad, mean you could accidentally edit an exe file!

I might change my script to:

Code: Select all

SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
FileGetSize, vSizeMB, % vPath, M
if (vExt = "lnk")
	FileGetShortcut, % vPath, vPath

Btw I noticed one thing in your code I wasn't really aware of:

Code: Select all

{MsgBox % "error"
Return
}

v.

{
MsgBox % "error"
Return
}

Interesting.

[EDIT:] Horstmann style v. Allman style.
Indentation style - Wikipedia
https://en.wikipedia.org/wiki/Indentation_style
Last edited by jeeswg on 10 May 2019, 10:20, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
nathan323
Posts: 41
Joined: 31 Jan 2016, 02:53

Re: Quicker way to open script file for editing

09 Jan 2017, 01:34

Btw I noticed one thing in your code I wasn't really aware of:

{MsgBox % "error"
Return
}

v.

{
MsgBox % "error"
Return
}

Interesting.
That was actually a typo that I caught after I'd posted (didn't think to check my post later, whoops).
nathan323
Posts: 41
Joined: 31 Jan 2016, 02:53

Re: Quicker way to open script file for editing

09 Jan 2017, 01:36

Code: Select all

#IfWinActive, ahk_class CabinetWClass
^Enter::
^NumpadEnter::
~!LButton up::
#IfWinActive, ahk_class ExploreWClass
^Enter::
^NumpadEnter::
~!LButton up::
#IfWinActive, ahk_class Progman
^Enter::
^NumpadEnter::
~!LButton up::
#IfWinActive, ahk_class WorkerW
^Enter::
^NumpadEnter::
~!LButton up::
This adds hotkey combo of Alt+single-click of left mouse button.
Works, but not ideal for two reasons.
  • 1. It's not consistent with the full-keyboard method (Ctrl key) - nor can that change to Alt because Alt+Enter is already used by Windows to display Properties dialog. (Though control+click/double-click without a second modifier won't work anyway because it just wants to select/deselect the file.)
    2. The file has to be single-clicked first to select it, before Alt+single-click will work. Bit of awkward double-handling there..
So I've changed the full-keyboard shortcuts to control+shift, and want to do the same for mouse (Ctrl+Shft+Left double-click).
I've looked at the help files and tried:

Code: Select all

Send^+{Click 2}::

Code: Select all

^+{MouseClick, left, , , 2}::

Few little variations, no luck. And its proven a hard thing to search for in forums, due to the number of results about remapping clicks to double-clicks..
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Quicker way to open script file for editing

09 Jan 2017, 02:05

I've never tried any double-click scripts.
The only thing I've tried with the mouse is right-click minimise button to minimise to the system tray.

This script is approaching working order.
I'm not sure how big a milliseconds gap constitutes a 'double-click'.
Also the first file you click on seems to sneak through and open.

Haha re. typo, my posts can always be more correct.
I always hope nobody looks at my posts in the first 7 minutes, when I'm still noticing minor code corrections and information clarifications.
Plus I'm always stripping my custom function references like JEE_MsgBox, JEE_RetX etc.
(JEE_RetX does Return plus hotkey log.)

Code: Select all

#IfWinActive ahk_class CabinetWClass
;LButton::
^LButton::
#IfWinActive ahk_class ExploreWClass
;LButton::
^LButton::
;if GetKeyState("Ctrl", "P")
;{
vTickCountLButton2 := vTickCountLButton
vTickCountLButton := A_TickCount
;}
if (vTickCountLButton - vTickCountLButton2 < 300)
	ToolTip, % "open file " vTickCountLButton
else
	ToolTip, % "do nothing"

SendInput, {LButton Down}
KeyWait, LButton
SendInput, {LButton Up}
return
Last edited by jeeswg on 10 May 2019, 10:24, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
lexikos
Posts: 6367
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Quicker way to open script file for editing

09 Jan 2017, 02:50

nathan323 wrote:I'm aware that you can hit Context+E, or right-click and Edit. What would be faster would be say holding Ctrl+Shft and double-clicking file.
Wouldn't right-click + E be faster? It's half as many clicks and keys...

AppsKey+E would be faster if both hands are on the keyboard and away from the mouse.
jeeswg wrote:I'm not sure how big a milliseconds gap
constitutes a 'double-click'.
DllCall("GetDoubleClickTime", "uint") will tell you.

Also, you could use A_TimeSincePriorHotkey when A_PriorHotkey = A_ThisHotkey.
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Quicker way to open script file for editing

09 Jan 2017, 02:54

Brilliant! 500 milliseconds says Windows 7.
Cheers for that tidbit, Lexikos.

One useful function I did know is DllCall("GetCaretBlinkTime"),
I use it to stop the caret from blinking when Notepad is idle.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
nathan323
Posts: 41
Joined: 31 Jan 2016, 02:53

Re: Quicker way to open script file for editing

09 Jan 2017, 04:31

I always hope nobody looks at my posts in the first 7 minutes,
when I'm still noticing minor code corrections
and information clarifications.
Hahaha. Sounds familiar ;)
Wouldn't right-click + E be faster? It's half as many clicks and keys...
I think for me, my left third and fourth fingers are always resting on control & shift anyway, so I don't have to "find" E, lol.

Cool, I'll check out this new info..

Return to “Ask For Help”

Who is online

Users browsing this forum: asad41163, frd, Google [Bot], Odlanir and 138 guests