Some time back, I found a script online that provides a shortcut to create a new file. It works great for my computer running Windows 7:

#IfWinActive, ahk_class CabinetWClass
#n:: ;If Windows+N is pressed in Windows Explorer
Send {Alt} ;Menu
Send f ;> File
Send w ;> New
Send t ;select Text Document
Send ^a ;select all
Exit

This script won't work for my new laptop running Windows 8. Was just wondering if anyone knows why this is, and if maybe there is a quick edit that can be made to make it work? Thanks for any help!

有帮助吗?

解决方案 2

This is due to the changed menu layout of Win 8 explorer. On my machine, if you press Alt in explorer, you will get overlaying images of buttons next to the corresponding menu which will be updated during menu navigation. You want to get to the Menu Home and then choose New item. On my machine, that's the key sequence Alt, R, W. But a subsequent shortcut to select text file (like T) doesn't seem to exist. On the other hand, AHK can do what you want without relying on the explorer menu, but that requires a bit of coding:

#IfWinActive, ahk_class CabinetWClass
#n::
    ControlGetText, dir, ToolbarWindow323
    RegExMatch(dir, ":(.*)", dir)
    dir := Trim(dir1)
    FileAppend, , %dir%\MyNewTextFile.txt
return

The only downside of this is that it won't work per se for folders you opened via "Favorites" or "Libraries" from explorer. But if you need them, you could still write a workaround for that.

其他提示

Think I actually came up with something that works in all contexts, Windows 7 and 8:

#n::
    Send {AppsKey}
    Send w
    Send t
    Sleep, 400
    Send ^+{Right}
    Send {Del}
return

I have to add the Sleep in there because it seems like it's trying to run the proceeding code before the file has time to be created. But this seems to accomplish what I need.

This works for Windows 10.

Create NewFile.txt by ctrl+shift+M

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

#IfWinActive ahk_class CabinetWClass
^+m::
    newFileHere()
    return
#IfWinActive

newFileHere(){
WinHWND := WinActive()
For win in ComObjCreate("Shell.Application").Windows
    If (win.HWND = WinHWND) {
        dir := SubStr(win.LocationURL, 9) ; remove "file:///"
        dir := RegExReplace(dir, "%20", " ")
        Break
    }

file = %dir%/NewFile.txt
if FileExist(file)
{
    MsgBox, NewFile.txt already exists
    return
}
FileAppend,, %file%  ; create new file
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top