# SDL: Fixed reporting backspace key if there is no text in the edit buffer (thanks @312937!)

**URL:** <https://discourse.libsdl.org/t/sdl-fixed-reporting-backspace-key-if-there-is-no-text-in-the-edit-buffer-thanks-312937/43888>\
**Category:** SDL Commits\
**Created:** [May 22, 2023, 7:02pm UTC](https://discourse.libsdl.org/t/sdl-fixed-reporting-backspace-key-if-there-is-no-text-in-the-edit-buffer-thanks-312937/43888 "2023-05-22T19:02:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [May 22, 2023, 7:02pm UTC](https://discourse.libsdl.org/t/sdl-fixed-reporting-backspace-key-if-there-is-no-text-in-the-edit-buffer-thanks-312937/43888/1 "2023-05-22T19:02:20Z")

</div>

> <https://github.com/libsdl-org/SDL/commit/c971795954bc85086cd20cfc71b45a311b7ba0d1>
>
> This workaround isn't necessary at API 30 and above.
> 
> Fixes https://github.com/l…ibsdl-org/SDL/issues/7039

```diff
From c971795954bc85086cd20cfc71b45a311b7ba0d1 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 22 May 2023 11:54:46 -0700
Subject: [PATCH] Fixed reporting backspace key if there is no text in the edit
 buffer (thanks @312937!)

This workaround isn't necessary at API 30 and above.

Fixes https://github.com/libsdl-org/SDL/issues/7039
---
 .../src/main/java/org/libsdl/app/SDLActivity.java | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index 5987fd87b339..2a676b96e9fa 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -2041,6 +2041,18 @@ public boolean setComposingText(CharSequence text, int newCursorPosition) {
 
     @Override
     public boolean deleteSurroundingText(int beforeLength, int afterLength) {
+ if (Build.VERSION.SDK_INT <= 29) {
+ // Workaround to capture backspace key. Ref: http://stackoverflow.com/questions>/14560344/android-backspace-in-webview-baseinputconnection
+ // and https://bugzilla.libsdl.org/show_bug.cgi?id=2265
+ if (beforeLength > 0 && afterLength == 0) {
+ // backspace(s)
+ while (beforeLength-- > 0) {
+ nativeGenerateScancodeForUnichar('\b');
+ }
+ return true;
+ }
+ }
+
         if (!super.deleteSurroundingText(beforeLength, afterLength)) {
             return false;
         }

```
