Created
December 18, 2023 12:55
-
-
Save fanlushuai/cd7056aaf72cb4cbaff60e793eeffca6 to your computer and use it in GitHub Desktop.
去除空行ahk脚本,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires AutoHotkey v2.0 | |
#SingleInstance Force | |
KeyHistory 0 | |
SendMode "Input" | |
global debug := False ;debug 输出开关 | |
getTextSelected() { | |
A_Clipboard := "" | |
Sleep 10 | |
Send "^c" | |
Sleep 10 | |
if !ClipWait(2) ; 最多等待 x s | |
{ | |
MsgBox "剪切板操作失败。确保您选中了文本" | |
return | |
} | |
global debug | |
if debug { | |
MsgBox A_Clipboard | |
} | |
return A_Clipboard | |
} | |
paste(text) { | |
A_Clipboard := text | |
Sleep 10 | |
Send "^v" | |
} | |
trimOneBlankLine(text) { | |
text := StrReplace(text, "`r`n`r`n", "`r`n") | |
text := StrReplace(text, "`r`n", "`r`n") | |
text := StrReplace(text, "`n`n", "`r`n") | |
text := StrReplace(text, "`r", "") | |
return text | |
} | |
trimAllBlankLine(text) { | |
text := StrReplace(text, "`r`n`r`n", "`r`n") | |
text := StrReplace(text, "`r`n", "`r`n") | |
newContent := "" | |
Loop parse, text, "`n", "`r" | |
{ | |
line := A_LoopField | |
lineTrim := Trim(line) | |
if (lineTrim != "") | |
newContent .= A_LoopField "`r`n" | |
} | |
return newContent | |
} | |
removeBlankLineOnSelected(){ | |
text := getTextSelected() | |
text := trimAllBlankLine(text) | |
paste(text) | |
} | |
#HotIf WinActive("ahk_exe winword.exe") or WinActive("ahk_exe wps.exe") or WinActive("ahk_exe code.exe") | |
; 删除选中文本。先选中,再调用 | |
^+s:: { | |
removeBlankLineOnSelected() | |
} | |
F4:: { | |
Send "^a" ;自动帮助用户选中 | |
removeBlankLineOnSelected() | |
} | |
; trimOneBlankLine 没有用武之地,不开森 | |
#HotIf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment