Command to rename selected file or folder

Get help with using AutoHotkey and its commands and hotkeys
LizardCobra
Posts: 14
Joined: 14 Feb 2020, 10:57

Command to rename selected file or folder

09 Apr 2020, 10:50

I want to set up a custom hotkey to enable renaming the selected file or folder in File Explorer. What command can I call to directly be able to rename the selected file or folder? I cannot just capture my custom hotkey and send F2 to accomplish this, because I am often running an application that uses F2 keyhooks. So the reason why I need a custom hotkey in the first place is that F2 cannot be used. What I need is the exact behavior of right clicking a file, then clicking Rename. Or selecting a file/folder and pressing F2. Then I can simply type the new name, and either type enter or click away to apply.

I've spent a long time searching forums, and I can't find anything that shows how enable a file to be renamed just by typing. I'm not providing a specific string for the new name, I want to be able to type a custom name on the fly.

The only part that I can figure out is determining if a File Explorer window is currently active. From there I need to verify that exactly one file is selected, get it's handle, and then simulate the Right Click-Rename.

Code: Select all

#ifWinActive, ahk_exe CabinetWClass

A related question; Is there anyway to disable the feature where clicking the name of a selected file causes it's name to be editable? I never ever do this intentionally, but I accidentally trigger this constantly.
User avatar
Scr1pter
Posts: 1200
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Command to rename selected file or folder

09 Apr 2020, 13:34

Hi,

When you use this command:
$F2::
there won't be a problem when your AHK script contains the line:
Send {F2}

Example:

Code: Select all

F2::
MsgBox, hello
return

F3::
Send {F2}
return
In that case, your F3 script will trigger the code which is inside of the F2 routine.

Code: Select all

$F2::
MsgBox, hello
return

F3::
Send {F2}
return
Here nothing will happen when you press F3, because F2 is prevented from tiggering.

I guess this might help you, because now you can assign Send {F2} to any script without triggering the F2-Script.

Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G15 FE - Mice: Logitech G9 FE, G502 FE, G602, Jelly Comb Touchpad - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.32.00
LizardCobra
Posts: 14
Joined: 14 Feb 2020, 10:57

Re: Command to rename selected file or folder

14 Apr 2020, 13:32

This won't work; it's not AutoHotKey that is responding to the F Key events, it's another application that I'm running. That application uses key hooks to trigger all of it's button events.
What I need is a way to do whatever happens when you right click and click "rename" directly. I just don't know how to do this. Is there a function already that will do this? Is there a such as a dll function that I can call?

Return to “Ask For Help”

Who is online

Users browsing this forum: TAC109 and 32 guests