2017-09-25 146 views

回答

1

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命令的工作方式不同:

+0

不錯。希望這對未來的某個人有用。 – HaveSpacesuit

1
^d::Send {Home}{ShiftDown}{End}{Right}{ShiftUp}{Del} 

可能並非在所有情況下,邊工作,但通過在記事本中一些非常基本測試。 =〜)

+0

謝謝!如果在線上有任何文字,您的答案就會很好。我更新了這個問題以刪除「文本」,因爲即使該行是空的,我也會喜歡它。我得到這樣的一個簡單的按下刪除鍵將在這種情況下工作,但試圖保持肌肉記憶相同。 :-D – GollyJer

+0

我調整了一些答案。沒有什麼太花哨,但它應該適用於空行和文件的最後一行。 – HaveSpacesuit

+0

適用於Word,SciTE4AutoHotkey和VisualStudio代碼。這些處理鍵盤命令的每一個都有點不同,但是它們在每一箇中的表現都一樣。再次感謝! – GollyJer

0

萬一你碰上,你需要不同的行爲不同程序的問題,您可以像這樣的具體方案「複製」你的^ d命令在Excel和Gmail中。