termux / termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.
https://f-droid.org/en/packages/com.termux
Other
35.57k stars 3.73k forks source link

Hardware Keyboard Mapping #1210

Open jpclouduk opened 5 years ago

jpclouduk commented 5 years ago

Feature description Currently there is limited key mapping options in termux.properties such as mapping the home button to ESC. Is it possible to also provide mapping of some special characters such as the "broken pipe" key to the "pipe" key? Something like; pipe-key=['¦'] No idea why all the bluetooth keyboards don't have a pipe key and the broken pipe character is rarely used in programming unlike "pipe".

Reference implementation No other emulator seems to have this feature or any key mapping options. Here is a typical BT keyboard, note the characters available and the "broken pipe". https://images-na.ssl-images-amazon.com/images/I/61n4an%2B5BOL.SL1000.jpg

Harshiv-Patel commented 4 years ago

The referenced character is not routinely used. Also there is no vertical broken bar character in given sample image.

If in bash you'd just use printf '\ua6' or in vim insert mode, ctrl+v 166 to insert it. Unless every 10th character you type is the broken pipe, you probably should not need to map it.

@fornwall Termux will hard crash if anything unexpected is found in $HOME/.termux/termux.properties other than standard key mappings, I think a null check or likewise is in order to point users in right direction like : "Unexpected character definition in termux.properties file, use Termux-failsafe mode to recover" and exit or load defaults, instead of crashing hard.

@jpclouduk I suppose what can be put in there is limited by mappings offerred by /system/user/keychars/Generic.kcm or the relevant Key Character Map file in use depending on the Hardware keyboard connected, or hardcoded by OEM in android framework, either way it's not easy to change that.

bubnikv commented 4 years ago

This is my quite old bluetooth keyboard (2012/13?) marketed for Android usage. The keyboard is quite nice, the keys are comparable with the keyboard in my Fujitsu laptop. However there is no function key row, no page up / down / home / end, no "FN" key to map the missing keys to. image

I have to admit that nowadays it seems that this kind of keyboard is out of fashion and most of the bluetooth keyboard with normal size keys that I could buy here in Czech Republic are equipped at least with mini function keys.

/system/user/keychars/Generic.kcm IMHO this could only be modified on rooted device.

It would be super useful to be able to do a full remapping in the TermuxApp, so I can for example reserve some key as a FN key to generate the missing key events with it.

Also interestingly enough the Microsoft Remote Desktop is able to capture the keyboard shortcuts that are normally swallowed by Android system (Alt-Tab for switching the applications etc). It would be great to have an option to suppress these system key combinations and to pass them to terminal. For example, on this particular keyboard, I may want to override the home, back, "search glass", volume up / down as keyboard modifiers or page up / down, home / end keys. That would really be great.

I know there are Android applications to do such remapping, but they are questionable: Some of them are commercial (I personally don't mind to pay if they worked and if they worked). They use questionable APIs, which may or may not be available on particular Android version or vendor model. They may consume unnecessary RAM and battery. They may log and send key presses to their authors. They may not work in Samsung DEX (desktop experience) mode. Also it makes sense to remap the keys in an application dependent way, thus remapping in Termux App makes sense.

bubnikv commented 4 years ago

These are the scan codes that the BT keyboard on the photo above produces:

Key Scan Code Comment
`~ 127 top left key, acts as menu on Android
caps lock 58
back 158 captured by the system / application to go back
search 217 captured by the application?
volume down 114 captured by the system for volume down / captured by the application
volume up 115 captured by the system for volume up / captured by the application
right shift 54
------------- ------------- --------------

The Home button is always captured by Android on newer systems and it cannot thus be remapped (at least this is what I read, I have to confirm with the Microsoft RDP client on Android, which captures all of the special keyboards above)..

I believe all the keys above are candidates for redefining as modifiers. For example, I would want to redefine the top left `~ key to its original purpose, I may redefine the caps lock as escape key, I may redefine the search light for the menu button, I may redefine volume up / down as page up / down, the back key as a Fn key to produce function keys together with numeric keys etc.

bubnikv commented 4 years ago

As a minimum implementation, it would be great, if the termux-app optionally handled the Volume-Up and Volume-Down buttons on the BT keyboard the same way it handles the Volume-Up/Down buttons on the phone. That way I could generate all the keys missing on my BT keyboard and I would have to memorize a single set of key combinations for both the touch keyboard and BT keyboard. I think this would make the owners of Android BT keyboards happy enough.