I'm using the solution from How to create a new text document (TXT) file by a Hotkey? since a few years, with Autohotkey, and it allows to create a new text file anywhere in the Windows explorer with a keyboard shortcut.

There is one drawback: when a file already has focus in the Explorer file list ("Details" view), it doesn't work, mainly because, when a file is selected, the Contextual menu doesn't show the "New > Text document".

Question: how to have a shortcut that creates a new text document, even if a file is currently selected in Details view of the Windows Explorer?

  • 2
    Add the command for the escape key to deselect the selected file at the start of the script? – Dave Oct 23 '18 at 7:13
  • 1
    @Dave Already tried, but doesn't work: go in Explorer, Details view in Windows 7. Click on a file (it will be selected/highlighted), then hit Escape, it will stay selected. – Basj Oct 23 '18 at 8:14

The File menu in Windows Explorer displays the New > Text Document menu option within a folder whether or not a file or folder is selected.

You can create a text document by simulating pressing Alt, f, w, t with this AutoHotkey script (bound to F4):

  Send {ALT}fwt
  • Yes @davidmneedham, it works great, except on Desktop (there, it doesn't). Would you have an idea of shortcut that works both on Desktop and in Windows Explorer / Details view? – Basj Oct 22 '18 at 22:17
  • @Basj you should edit your question to indicate that you want it to function both on the Desktop and within Windows Explorer. (user3419297's answer)[superuser.com/a/1369167/206587] is one option that fits your use case. – davidmneedham Oct 23 '18 at 15:21
#If (WinActive("ahk_class Progman") || WinActive("ahk_class WorkerW") || WinActive("ahk_class CabinetWClass"))   ; desktop or explorer

    WinGet, active_id, ID, A
    InputBox, name, Create a New Text Document, Enter a name:,, 300, 120
    If !ErrorLevel
        WinActivate, ahk_id %active_id%
        If WinActive("ahk_class Progman") or WinActive("ahk_class WorkerW") ; desktop
            FileAppend,, %A_Desktop%\%name%.txt
            Run, %A_Desktop%\%name%.txt
        if WinActive("ahk_class CabinetWClass") ; explorer
            WinGetTitle, ActiveTitle, A
            If InStr(ActiveTitle, "\")  ; If the full path is displayed in the title bar (Folder Options)
                Folderlpath := ActiveTitle
            If InStr(ActiveTitle, ":") ; If the title displayed is something like "DriveName (C:)"
                Folderlpath := SubStr(ActiveTitle, -2)
                Folderlpath := SubStr(Folderlpath, 1, -1)
            else ; If the full path is NOT displayed in the title bar 
            ; https://autohotkey.com/boards/viewtopic.php?p=28751#p28751
            for window in ComObjCreate("Shell.Application").Windows
                try Folderlpath := window.Document.Folder.Self.Path
                SplitPath, Folderlpath, title
                If (title = ActiveTitle)
            FileAppend,, %Folderlpath%\%name%.txt
            Run, %Folderlpath%\%name%.txt


As an addendum to the original script you were using, you can do the following:

!h, sn           ; <-- this is what you want, ALT is denoted by !
Click, Right, 1
Sleep, 10
SendRaw, wt

(ALT+H, SN = select none)

Which is to say, do ALT+H then S followed by N. This effectively does a "Select None" then proceeds to emulate the context menu method of creating said file.

This works in File Explorer and the Desktop, although this was Windows 10, I'd assume this would work in Windows 7.

  • What does ALT+H do? For me (Win7), it does show the Help menu of the Explorer window, so it does not work. – Basj Oct 24 '19 at 22:44

I'm finally using:

  • @davidmneedham's solution when in Explorer window: Alt, f, w, t

  • Right click and w, t in other cases (such as Desktop)

Here is the code:

#IfWinActive ahk_class CabinetWClass
F4:: Send {ALT}fwt

Send wt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.