InputBox to rename selected file in Explorer (avoids annoying Windows autoselect)

Post your working scripts, libraries and tools
jhillert
Posts: 2
Joined: 14 Mar 2017, 13:22
GitHub: jehillert

InputBox to rename selected file in Explorer (avoids annoying Windows autoselect)

28 Mar 2018, 02:08

; In some cases, Windows automatically re-selects the entire file name when renaming a file via F2.
; I have searched for how to disable this behavior and have not found a solution. This script uses
; InputBox as a work-around. It works on renaming multiple files as well. If anyone knows the real
; registry that fixes the problem, please do reply here.

F2::Explorer_RenameSelectedFile()

Explorer_RenameSelectedFile() {
MouseGetPos, rnx, rny
ControlGetPos, cx, cy
ControlGetFocus, thisControl, A
if (thisControl != "DirectUIHWND3") {
exit
}
Menu, Tray, Icon, imageres.dll, 204
file_name := Explorer_ReturnFileName()
InputBox, new_name, Rename File, , , 250, 100, %cx%, %cy%,,,%file_name%
if (ErrorLevel) {
Menu, Tray, Icon, autotext.ico
Exit
} else {
SendInput {F2}
SendInput %new_name%
SendInput {Enter}
}
Menu, Tray, Icon, autotext.ico
}
Explorer_GetSelection(hwnd="") {
hwnd := hwnd ? hwnd : WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (class="CabinetWClass" or class="ExploreWClass" or class="Progman")
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
sel := window.Document.SelectedItems
for item in sel
ToReturn .= item.path "`n"
return Trim(ToReturn,"`n")
}
Explorer_ReturnFileName(hwnd="") {
file_path := Explorer_GetSelection(hwnd)
SplitPath, file_path, , , , file_name
return file_name
}
User avatar
Delta Pythagorean
Posts: 567
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: InputBox to rename selected file in Explorer (avoids annoying Windows autoselect)

28 Mar 2018, 03:03

Psst, use the

Code: Select all

 blocks!

- [AHK].......: 1.1.33.02 Unicode 64-bit
- [OS].........: Windows 10.0.18362
- [GITHUB]...: github.com/DeltaPyth
- [PAYPAL]....: paypal.me/DelPyth
- [DISCORD]..: Delta#3324

Remember to use [code]CODE[/code] for your multi-line scripts.
Stay safe, stay inside, and remember to wash your hands for 20 seconds!
jhillert
Posts: 2
Joined: 14 Mar 2017, 13:22
GitHub: jehillert

Re: InputBox to rename selected file in Explorer (avoids annoying Windows autoselect)

28 Mar 2018, 20:07

Yeah, I was really tired when I put that up. Now that I know posts cannot be deleted (this was my first submission), and after finding a dozen problems (I didn't test it), I think it in my best interest for that up there to remain incomprehensible until I come up with something that doesn’t make me feel like I drunk dialed my friends mom but cannot remember which friend it was...

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 18 guests