How to backspace a sentence till dot, comma, etc Topic is solved
-
- Posts: 6
- Joined: 08 Jan 2021, 02:43
How to backspace a sentence till dot, comma, etc
As the {Ctrl Down}{Backspace}{Ctrl Up} backspace a word how to backspace a sentence till the dot. Comupter recognizes that a word has finish in this example but how to make delete a sentence till dot, comma semi colon, colon, question mark and this "|" line type thing. I have read about the script that backspace a line till the start, but this backspacing till dot require some other coding that I don't know. I want a code that backspaces the line till the up mentioned marks and does it instantly like the {Ctrl Down}{Backspace}{Ctrl Up} code does.
Last edited by gregster on 30 Nov 2021, 01:37, edited 1 time in total.
Reason: Topic moved from 'About This Community'.
Reason: Topic moved from 'About This Community'.
Re: How to backspace a sentence till dot, comma, etc
Hallo,
perhaps?:
perhaps?:
Code: Select all
F1::
ClipSaved := ClipBoardAll
SendInput, ^{Left}
Loop
{
ClipBoard =
SendInput, ^+{Left}^c
ClipWait, 0
IF ErrorLevel Or RegExMatch(ClipBoard, "[,;:.?|]")
Break
SendInput, {Bs}
}
SendInput, ^{Right}
ClipBoard := ClipSaved
Return
Re: How to backspace a sentence till dot, comma, etc
This works in Notepad but might not work in some other programs.
Code: Select all
controlName := "Edit1", find := ".,;:?|"
#IfWinActive ahk_exe notepad.exe
F3::
ControlGet, row , CurrentLine,, %controlName% ; Cursor's line number
ControlGet, col , CurrentCol ,, %controlName% ; Cursor's column number
ControlGet, line, Line, %row% , %controlName% ; Text of the current line
pos := pos2 := 0
While pos2 := RegExMatch(line, "[" find "]", char, pos2 ? pos2 + 1 : 1)
pos := pos2 < col ? pos2 : pos
SendInput % pos ? "{BS " col - pos - 1 "}" : ""
Return
#IfWinActive
-
- Posts: 6
- Joined: 08 Jan 2021, 02:43
Re: How to backspace a sentence till dot, comma, etc Topic is solved
@Rohwedder , your code is working but at the end of the sentence it was leaving a word due to the ^{Left} input at the start. I changed the script to the following according to my usage and it is working nicely. The only issue that I am getting is that it is not that fast but does the job. It is even slow in the word or other heavy programme other than notepad.
Code: Select all
F3::
ClipSaved := ClipBoardAll
SendInput, {BackSpace 3}
Loop
{
ClipBoard =
SendInput, ^+{Left}^c
ClipWait, 0
IF ErrorLevel Or RegExMatch(ClipBoard, "[,;:.?|]")
Break
SendInput, {Bs}
}
SendInput, ^{Right}
ClipBoard := ClipSaved
return
-
- Posts: 6
- Joined: 08 Jan 2021, 02:43
Re: How to backspace a sentence till dot, comma, etc
Sir, I can get this code to work even in the noteopad. It is note responding. When I press the hotkey it does not do anything.mikeyww wrote: ↑30 Nov 2021, 07:28This works in Notepad but might not work in some other programs.
Code: Select all
controlName := "Edit1", find := ".,;:?|" #IfWinActive ahk_exe notepad.exe F3:: ControlGet, row , CurrentLine,, %controlName% ; Cursor's line number ControlGet, col , CurrentCol ,, %controlName% ; Cursor's column number ControlGet, line, Line, %row% , %controlName% ; Text of the current line pos := pos2 := 0 While pos2 := RegExMatch(line, "[" find "]", char, pos2 ? pos2 + 1 : 1) pos := pos2 < col ? pos2 : pos SendInput % pos ? "{BS " col - pos - 1 "}" : "" Return #IfWinActive
Re: How to backspace a sentence till dot, comma, etc
If the cursor is positioned after a punctuation mark, then nothing happens because the goal has already been met.
-
- Posts: 6
- Joined: 08 Jan 2021, 02:43
Re: How to backspace a sentence till dot, comma, etc
Sir, Just 2 last questions.
1. When the backspacing process has reached the very first line then it stops deleting because it is obvious that there is no recognizable mark at the start. Can you please make it also delete the first line?
2. Can you make it work in every application or any text box anywhere?
This was my first post. Thank you all for supporting @Rohwedder @mikeyww . I don't thought it was such a healthy environment. Thank you. Sorry for the bad english.
Re: How to backspace a sentence till dot, comma, etc
maybe , an example to cut existing text
Code: Select all
text=
(Ltrim join`r`n
Windows 11’s hardware= requirements = are strict
This is undoubtedly the biggest: barrier to entry - millions of Windows 10 devices simply aren’t compatible with Windows 11. Microsoft has made the hardware requirements much stricter as it prioritises security, with a recent 1GHz processor, TPM 2.0 and Secure Boot among the most controversial updates. There are ways to get around this, of course, but most people won’t be comfortable running Windows 11 on a device that’s not supported by Microsoft.
Is this the last line ? No I continue with test . https://www.techadvisor.com/news/windows/windows-11-why-havent-more-people-upgraded-3811404/
)
text1 := RegExReplace(text, "([. ! ? : = - ] )", "$1`r`n")
Fileappend,%text1%`r`n,test21.txt,utf-8
run,test21.txt
return
/*
Windows 11’s hardware=
requirements =
are strict
This is undoubtedly the biggest:
barrier to entry - millions of Windows 10 devices simply aren’t compatible with Windows 11.
Microsoft has made the hardware requirements much stricter as it prioritises security, with a recent 1GHz processor, TPM 2.0 and Secure Boot among the most controversial updates.
There are ways to get around this, of course, but most people won’t be comfortable running Windows 11 on a device that’s not supported by Microsoft.
Is this the last line ?
No I continue with test .
https://www.techadvisor.com/news/windows/windows-11-why-havent-more-people-upgraded-3811404/
*/
Re: How to backspace a sentence till dot, comma, etc
This version works across multiple lines.
Code: Select all
controlName := "Edit1", find := ".,;:?|"
#IfWinActive ahk_exe notepad.exe
F3::
absPos := pos := pos2 := 0
ControlGetText, cText, %controlName%
ControlGet, row , CurrentLine,, %controlName% ; Cursor's line number
ControlGet, col , CurrentCol ,, %controlName% ; Cursor's column number
ControlGet, line, Line, %row% , %controlName% ; Text of the current line
For lineNum, line in StrSplit(cText, "`r`n") ; Get position within all text
absPos += lineNum < row ? StrLen(line) + 2 : lineNum = row ? col : 0
While pos2 := RegExMatch(cText, "[" find "]",, pos2 ? pos2 + 1 : 1)
pos := pos2 <= absPos ? pos2 : pos
RegExReplace(SubStr(cText, 1, pos), "`n",, count)
SendInput % pos ? "{BS " absPos - pos - 1 - (row - (pos ? count + 1 : 0)) "}" : ""
Return
#IfWinActive
-
- Posts: 6
- Joined: 08 Jan 2021, 02:43
Re: How to backspace a sentence till dot, comma, etc
Can this work in word, please?mikeyww wrote: ↑01 Dec 2021, 11:43This version works across multiple lines.
Code: Select all
controlName := "Edit1", find := ".,;:?|" #IfWinActive ahk_exe notepad.exe F3:: absPos := pos := pos2 := 0 ControlGetText, cText, %controlName% ControlGet, row , CurrentLine,, %controlName% ; Cursor's line number ControlGet, col , CurrentCol ,, %controlName% ; Cursor's column number ControlGet, line, Line, %row% , %controlName% ; Text of the current line For lineNum, line in StrSplit(cText, "`r`n") ; Get position within all text absPos += lineNum < row ? StrLen(line) + 2 : lineNum = row ? col : 0 While pos2 := RegExMatch(cText, "[" find "]",, pos2 ? pos2 + 1 : 1) pos := pos2 <= absPos ? pos2 : pos RegExReplace(SubStr(cText, 1, pos), "`n",, count) SendInput % pos ? "{BS " absPos - pos - 1 - (row - (pos ? count + 1 : 0)) "}" : "" Return #IfWinActive
Re: How to backspace a sentence till dot, comma, etc
I'm not so sure that Word uses a standard edit control. You may have better luck with Rohwedder's script there.
-
- Posts: 6
- Joined: 08 Jan 2021, 02:43