5

I want to create a new text file by right click -> New -> New text document using AutoHotKey. How do I do this? I am new to AutoHotKey.

Edit:

Using Autohotkey, you can assign shortcut for some tasks such as running a particular program like Notepad. You do so by writing scripts. You can find the details on the Autohotkey website. I want to write a keyboard shortcut to manually automate the "right click -> New -> New text document" functionality.

I figured out that it could be done by adding the following script to to AutohotKey's existing script.

^+t::
  Click, right, 1024, 355 (or any other mouse co-ordinates for that matter)
  Send w
  Send t
 return

However, this syntax wouldn't work when I tried. Could someone tell me what's wrong and tell how should be the correct syntax?

TheRookierLearner
  • 3,643
  • 8
  • 35
  • 53
  • What does this have to do with AutoHotkey? "Right-click" what? You can do this already with Windows Explorer without AutoHotkey. – Ken White Apr 20 '13 at 00:49
  • I copying the addresses from the address bar of the Windows Explorer. So in order to have the "Right-click" key, I need to click on the center (or some other part of the screen) to get the focus back to the work area. Hence, autohotkey. I'm getting lazy i guess ;) – TheRookierLearner Apr 20 '13 at 00:56
  • I know you want to resolve something, but I still don't understand what it is that you want, how you want to solve it and what the steps are, that you have to take manually right now, which you want to get automated. Without that how do you think we can help you? – Robert Ilbrink Apr 20 '13 at 05:13
  • Why down-vote? Initially, it wasn't very much of a good question, but after the edit, I guess it was ok. – TheRookierLearner Apr 20 '13 at 19:14
  • Hey - Seeing as autohotkey is apparently off topic - I've created a AHK proposal at Area 51 area51.stackexchange.com/proposals/103457/autohotkey – dwjohnston Oct 06 '16 at 23:18

1 Answers1

3

As Ken White said you already have that built in Windows Explorer, Right click > New > New Text Document, so it's kinda pointless having another one doing the same thing.

However, if you want to use AutoHotKey to create a new text file more efficiently and faster then i would recommend this script

SetTitleMatchMode RegEx
MsgBox, 64, NewTextFile, USAGE: When in a folder in Windows Explorer press Ctrl + Shift + T to create empty text file.`nIf you press multiple times, multiple files will be created (e.g. NewTextFile0.txt, NewTextFile1.txt)

#IfWinActive ahk_class ExploreWClass|CabinetWClass
    ^+t::
        NewTextFile()
        return
#IfWinActive

NewTextFile()
{
    WinGetText, full_path, A
    StringSplit, word_array, full_path, `n
    Loop, %word_array0%
    {
        IfInString, word_array%A_Index%, Address
        {
            full_path := word_array%A_Index%
            break
        }
    } 
    full_path := RegExReplace(full_path, "^Address: ", "")
    StringReplace, full_path, full_path, `r, , all

    IfInString full_path, \
    {
        NoFile = 0
        Loop
        {
            IfExist  %full_path%\NewTextFile%NoFile%.txt
                    NoFile++
                else
                    break
        }
        FileAppend, ,%full_path%\NewTextFile%NoFile%.txt
    }
    else
    {
        return
    }
}

When you have this running and you are in a folder using Windows Explorer (or Desktop) press Ctrl+Shift+T to create New text files, as many as you'd like.

https://github.com/ilirb/ahk-scripts/blob/master/executable/source/NewTextFile.ahk

IlirB
  • 1,410
  • 14
  • 19
  • It worked for me only when I've changed `#IfWinActive ahk_class ExploreWClass|CabinetWClass` into `#If WinActive("ahk_class ExploreWClass") || WinActive("ahk_class CabinetWClass")` – BornToCode Jan 29 '16 at 03:42
  • Hey - Seeing as autohotkey is apparently off topic - I've created a AHK proposal at Area 51 http://area51.stackexchange.com/proposals/103457/autohotkey – dwjohnston Oct 06 '16 at 23:17