question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create proper Ctrl+Backspace shortcut in TextBox

See original GitHub issue

In Windows, Ctrl+Backspace commonly serves as a shortcut to delete the word immediately preceding the cursor. It is equivalent to Ctrl+Shift+Left followed by Backspace.

In WinForms, this shortcut works only in single-line TextBox controls which have autocomplete enabled. This is actually built into SHAutoComplete somewhere in the win32 API, and is a “rogue feature” with no documentation (some history here). If the TextBox is multi-line or doesn’t have autocomplete on, Ctrl+Backspace inserts a DELETE character (ASCII 127) instead.

Note: The Ctrl+Delete shortcut (which deletes the word following the cursor) works in all relevant WinForms controls.

Outside of WinForms, the Ctrl+Backspace shortcut is nearly ubiquitous on Windows (as of October 2018, even Notepad finally has it!). As such, I propose properly implementing it in WinForms controls such as TextBoxBase and ComboBox with a custom handler for Ctrl+Backspace.


I’ve submitted a PR with one approach to add this shortcut, namely using SendInput sending native messages to simulate the aforementioned Ctrl+Shift+Left, Backspace keystrokes. I believe this is the right approach — as even the current autocomplete TextBox “feature” seems to be selecting the text and then deleting it if you watch closely.

Another possibility would be to use internal text selection functions rather than sending keystrokes. However, that requires replicating the logic dealing with word boundaries/punctuation currently used by Ctrl+Shift+Left, which is a bit quirky, not to mention wildly inconsistent between different Windows programs. We can consider this approach if the current PR is lacking.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
ArrowCasecommented, Dec 19, 2018

@zsd4yr WinForms has a custom “select all” shortcut handler for multi-line TextBox controls here with a comment explicitly calling out the intent to support something that the native control doesn’t.

/// Native “EDIT” control does not support “Select All” shorcut represented by Ctrl-A keys, when in multiline mode, /// and historically Winforms TextBox did not support it either. /// We are adding support for this shortcut for application targeting 4.6.1 and newer[…]

1reaction
jnm2commented, Dec 19, 2018

I live by Ctrl+Back/Del/Left/Right. It doesn’t have the awareness of users and implementors that it should have for how much it improves quality of keyboard usage.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Winforms Textbox - Using Ctrl-Backspace to Delete Whole ...
Enable autocompletion for the textbox and CTRL-Backspace should work as you want it to. CTRL-Backspace deleting whole word to the left of ...
Read more >
Adding CTRL-A and CTRL-Backspace Support to the ...
Two of those are keyboard shortcuts found on the the WinForms Textbox: CTRL+A (to select all text) and CTRL+Backspace (to delete the previous...
Read more >
Ctrl + Backspace in TextEdit and TextBox inserts a character
In many cases, Ctrl + Backspace inserting a character seems counter-intuitive. It should at least act as a regular backspace.
Read more >
Notepad Ctrl-Backspace behavior
Text fields in almost all software erase a word when ctrl + backspace is pressed. However, Notepad behaves differently, and inserts a character ......
Read more >
How can I set up a keyboard shortcut so that Ctrl ...
In Kubuntu Ctrl + Backspace by default is assigned to the action "Delete Word Backwards" which is used by some applications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found