1
votes

I want define a custom hotkey to rename a selected file in File Explorer. So my new hotkey should behave exactly like the F2 key does by default. That is, when I press the hotkeys, the file name should be editable, allowing me to type a new name. However, I can't use the F2 key to cause windows to do this.

The reason is that I'm using the default hotkeys for something else. I am often running an application (unrelated to AutoHotKey) where the buttons in the UI are triggered using keyhooking for all of the F keys. The only suggestions that I can find on this are to have my custom hotkey use 'send' to raise the default key codes that would be associated with the action. This won't work, because I am using those hotkeys for something else. What I need is a solution that causes a file to be renameable without sending the F2 keycode.

 ^+!R::
Send {F2} ;This won't work for me
return
1
You could use COM to get the current selected file and then rename it programmatically, and not via just using normal Windows renaming. Is this something you'd be interested in?0x464e
@0x464e, yes, that sounds like what I was envisioning doing.Bernoulli Lizard
What is the COM command to rename the file?Bernoulli Lizard

1 Answers

2
votes

Actually the original hotkey can be used, just add $ before the hotkey that you don't want to be fired by the send command. Also using app-specific hotkeys a good idea to minimize possible conflicts.
Try this:

#If winActive("ahk_exe Explorer.EXE") 

^+!R::
    send {F2}
return

$F2::
    send {down}
return  

In case you have an application which scans the F2 key globally and unconditionally, and you cannot redefine it, there is not much you can do from within AHK. So ideally you should get rid of that application, and use e.g. AHK for same functionality, or find some workaround.
In this particular case the easiest workaround is alternative way to rename the file:

^+!R::
    send {AppsKey}
    sleep 100
    send {m}
return