Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; AutoHotkey v2
- global lastC := 0
- global lastX := 0
- global clickTimerC := false
- global clickTimerX := false
- GetActivePath() {
- hwnd := WinActive("A")
- for window in ComObject("Shell.Application").Windows {
- try {
- if (window.HWND == hwnd)
- return window.Document.Folder.Self.Path
- } catch {
- continue
- }
- }
- return ""
- }
- AskFileName(ext) {
- input := InputBox("Введите имя файла (без расширения):", "Создание " . ext)
- if input.Result = "Cancel"
- return ""
- return input.Value != "" ? input.Value : "file"
- }
- CreateFile(path, filename) {
- full := path "\" filename
- if FileExist(full) {
- TrayTip "Уведомление", "Файл уже существует: " filename, 2
- return
- }
- dotPos := InStr(filename, ".", , -1)
- ext := SubStr(filename, dotPos + 1)
- name := SubStr(filename, 1, dotPos - 1)
- content := ""
- if ext = "h" || ext = "hpp" {
- guard := RegExReplace(name, "\W", "_")
- guard := StrUpper(guard) . "_" . StrUpper(ext)
- content := "#ifndef " . guard . "`n"
- content .= "#define " . guard . "`n`n"
- content .= "`n"
- content .= "#endif // " . guard . "`n"
- }
- FileAppend(content, full)
- TrayTip "Создан файл", filename, 2
- }
- ; --- Стандартные ---
- #!t:: {
- path := GetActivePath()
- if path != "" {
- name := AskFileName("txt")
- if name != ""
- CreateFile(path, name . ".txt")
- }
- }
- #!s:: {
- path := GetActivePath()
- if path != "" {
- name := AskFileName("swift")
- if name != ""
- CreateFile(path, name . ".swift")
- }
- }
- ; --- Ctrl + Alt + C: одиночное → .c, двойное → .h ---
- #!c:: {
- global lastC, clickTimerC
- now := A_TickCount
- if (now - lastC < 400) {
- clickTimerC := false
- path := GetActivePath()
- if path != "" {
- name := AskFileName("h")
- if name != ""
- CreateFile(path, name . ".h")
- }
- } else {
- lastC := now
- clickTimerC := true
- SetTimer(() => HandleSingleC(), -400)
- }
- }
- HandleSingleC() {
- global clickTimerC
- if clickTimerC {
- path := GetActivePath()
- if path != "" {
- name := AskFileName("c")
- if name != ""
- CreateFile(path, name . ".c")
- }
- }
- clickTimerC := false
- }
- ; --- Ctrl + Alt + X: одиночное → .cpp, двойное → .hpp ---
- #!x:: {
- global lastX, clickTimerX
- now := A_TickCount
- if (now - lastX < 400) {
- clickTimerX := false
- path := GetActivePath()
- if path != "" {
- name := AskFileName("hpp")
- if name != ""
- CreateFile(path, name . ".hpp")
- }
- } else {
- lastX := now
- clickTimerX := true
- SetTimer(() => HandleSingleX(), -400)
- }
- }
- HandleSingleX() {
- global clickTimerX
- if clickTimerX {
- path := GetActivePath()
- if path != "" {
- name := AskFileName("cpp")
- if name != ""
- CreateFile(path, name . ".cpp")
- }
- }
- clickTimerX := false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement