Here are detailed steps to be able to use buttons with the screen off without rooting your phone. You only need to do most of this setup once, but you will need to run the adb shell command every time you reboot your phone.
Please note that this does not work on all phones due to hardware limitations.
1. Install Button Mapper from the Play Store and follow the directions to enable the Accessibility service
2. Download adb and Install on your PC
3. Enable USB Debugging Mode on your phone. Go to System Settings and type “Build number” in the searchbar. Select “Build number” from the list, then tap it seven times to enable Developer Options. Go back to Settings, scroll to the bottom of the list and select Developer Options. In Developer Options, enable USB debugging.
4. Connect your phone to your PC with the USB cable. A dialog will pop up when the phone connects to the PC, be sure to allow USB Debugging
5. On your phone, open Button Mapper, select “Screen off actions.” A dialog will pop up asking to enable permissions.
6. On your PC, open a command prompt (or PowerShell) and type the following exactly:
adb shell sh /data/data/flar2.homebutton/keyevent.sh
7. Back on your phone, close the dialog and click on Screen off actions again. This time the switch will turn on.
Now your remapped buttons will work with the screen off!
Start writing or type / to choose a block