如何使用AutoHotkey删除当前行?
HaveSpacesuit的答案有效,但使用它一段时间后,我意识到它会删除活动行,有时会重新定位下面行的间距。
这使我重新思考他的解决方案。我不是从前线走到后面,而是试着从后向前走。这解决了重新定位问题。
SendInput {End}
SendInput +{Home}
SendInput ^+{Left}
SendInput {Delete}
虽然还有一个小问题。如果光标位于空行上,并且上面有更多空行,则所有空行都会被删除。
我不知道一个关键组合,以取代^+{Left}
没有这种行为,所以我不得不写一个更全面的解决方案。
^d:: DeleteCurrentLine()
DeleteCurrentLine() {
SendInput {End}
SendInput +{Home}
If get_SelectedText() = "" {
; On an empty line.
SendInput {Delete}
} Else {
SendInput ^+{Left}
SendInput {Delete}
}
}
get_SelectedText() {
; See if selection can be captured without using the clipboard.
WinActive("A")
ControlGetFocus ctrl
ControlGet selectedText, Selected,, %ctrl%
;If not, use the clipboard as a fallback.
If (selectedText = "") {
originalClipboard := ClipboardAll ; Store current clipboard.
Clipboard := ""
SendInput ^c
ClipWait .2
selectedText := ClipBoard
ClipBoard := originalClipboard
}
Return selectedText
}
据我所知,这不会产生意外的行为。
不过,如果您使用的是剪贴板管理,因为这脚本使用剪贴板,如果必要的话,作为中介,以获得选定的文本要小心。这将影响剪贴板管理器历史记录。
SetTitleMatchMode, 2 ; Makes the #IfWinActive name searching flexible
^d::Send {Home}{ShiftDown}{End}{Right}{ShiftUp}{Del} ; Generic response to ^d.
#IfWinActive, Gmail ; Gmail specific response
^d::Send {Home}{ShiftDown}{End}{Right}{ShiftUp}{Del} ; adapt this line for gmail
#IfWinActive ; End of Gmail's specific response to ^d
#IfWinActive, Excel ; Excel specific response.
^d::Send {Home}{ShiftDown}{End}{Right}{ShiftUp}{Del} ; adapt this line for Excel
#IfWinActive ; End of Excel's specific response to ^d
这样你的^ d命令的工作方式不同:
^d::Send {Home}{ShiftDown}{End}{Right}{ShiftUp}{Del}
可能并非在所有情况下,边工作,但通过在记事本中一些非常基本测试。 =〜)
谢谢!如果在线上有任何文字,您的答案就会很好。我更新了这个问题以删除“文本”,因为即使该行是空的,我也会喜欢它。我得到这样的一个简单的按下删除键将在这种情况下工作,但试图保持肌肉记忆相同。 :-D – GollyJer
我调整了一些答案。没有什么太花哨,但它应该适用于空行和文件的最后一行。 – HaveSpacesuit
适用于Word,SciTE4AutoHotkey和VisualStudio代码。这些处理键盘命令的每一个都有点不同,但是它们在每一个中的表现都一样。再次感谢! – GollyJer
万一你碰上,你需要不同的行为不同程序的问题,您可以像这样的具体方案“复制”你的^ d命令在Excel和Gmail中。
不错。希望这对未来的某个人有用。 – HaveSpacesuit