[GUIDE] How to get good Ctrl and Alt keys in SSH while keeping Fn

Search This thread

zx2c4

Recognized Developer
Sep 12, 2013
213
852
Paris
www.zx2c4.com
Hi folks. I use JuiceSSH. In the current CM settings, it interprets the hardware alt key as an actual console alt. This is nice for changing windows in irssi (Alt+1, Alt+2, ...), but it's not useful for getting at the Fn keys for special characters. It would be nice to have Fn, Ctrl, and Alt, all working. Here's how to get this done:

View this: hxxp://data.zx2c4.com/galaxy-relay-keyboard-map.jpg

The file /system/usr/keylayout/sec_keypad.kl contains correlations of keycodes and keychars. It turns out JuiceSSH interprets ALT_LEFT as console alt, ALT_RIGHT as Fn, and CTRL_LEFT as console ctrl. So in that file, we want to remap ALT_LEFT to ALT_RIGHT, and then remap the MAIL and CHAT keys to CTRL_LEFT and ALT_LEFT respectively:

Code:
key 56    ALT_RIGHT         WAKE_DROPPED
key 155  CTRL_LEFT          WAKE_DROPPED
key 429  ALT_LEFT           WAKE_DROPPED
key 217  META_LEFT          WAKE_DROPPED

The full keycode file is available at hxxp://data.zx2c4.com/sec_keypad_modified.kl .

Here's a command listing of how I enable this using adb:

Code:
zx2c4@thinkpad ~ $ adb shell
shell@android:/ $ su
root@android:/ # mount -o rw,remount /system
root@android:/ # wget -O /system/usr/keylayout/sec_keypad.kl hxxp://data.zx2c4.com/sec_keypad_modified.kl
root@android:/ # reboot

In practice, this thus far works very well.

Remember to change "hxxp" in this post; as a new member of XDA, I'm not allowed to post links.
 
Last edited:

Calchan

Member
Aug 28, 2013
8
1
I don't use JuiceSSH (but I'll definitely try it at some point if only for mosh), so I tried that with the built-in terminal app. By the way I don't know what version of CM 10.2 you're using, but here on the 20130909 nightly I found the kymaps in /system/usr/keylayout and not in /system/usr/keymap.

I didn't remap ALT_LEFT, but did remap 155 to CTRL_LEFT and 429 to META_LEFT like you did. I also remapped 217 to ESCAPE which is very handy in vim. Here's the diff:

--- sec_keypad.kl.orig 2013-09-12 17:55:28.434192677 -0600
+++ sec_keypad.kl 2013-09-12 18:12:08.876521089 -0600
@@ -81,3 +81,3 @@
-key 155 ENVELOPE WAKE_DROPPED
-key 429 CONTACTS WAKE_DROPPED
-key 217 SEARCH WAKE_DROPPED
+key 155 CTRL_LEFT WAKE_DROPPED
+key 429 META_LEFT WAKE_DROPPED
+key 217 ESCAPE WAKE_DROPPED

The ESCAPE works but not the CTRL_LEFT and META_LEFT. The remapping does seem to work since the keys don't do any longer what they used to do. So I'm guessing it's the key compositing that doesn't work.

I'll keep looking.
 
  • Like
Reactions: computerinfo21

zx2c4

Recognized Developer
Sep 12, 2013
213
852
Paris
www.zx2c4.com
I found the kymaps in /system/usr/keylayout and not in /system/usr/keymap.
Typo! My bad; fixed above.

ESCAPE which is very handy in vim.
That does indeed seem quite handy. I'm tempted to remap the mic button away from META how it is now (which is a bit useful but not super) and toward escape for vim. Good idea.

Having a working ctrl and alt key for android itself, not just the terminal, is proving invaluable. Ctrl+A, ctrl+C, ctrl+V, alt+left, alt+shift+left, etc -- all really nice to have when editing text.
 
N

Nardholio

Guest
You will most likely have to recompile the kernel to change those to alt and ctrl keys. The keys are laid out in board-apexq.c and they are mapped with standard linux keycode names from input.h.
 

Calchan

Member
Aug 28, 2013
8
1
That does indeed seem quite handy. I'm tempted to remap the mic button away from META how it is now (which is a bit useful but not super) and toward escape for vim. Good idea.

Key 214 is indeed the microphone key, and having that mapped to ESCAPE like I did is very handy. What is META used for?

Can you please try the CTRL and ALT keys in the defaut CM terminal and tell me if they work for you? I haven't had time yet to try in JuiceSSH yet, but they don't work in the default terminal here.
 

cybertim

Member
Jan 20, 2013
15
3
I used your fix to make JuiceSSH working on my Relay (yes i bought one only for the keyboard/ssh - can't do that on my expensive N5)

It looks like the arrow keys are mapped 'backward' and some alt-<combination> keys (like the '.com') arn't working, is this correct?

[edit]
I fixed it (or it has been fixed by updating to a newer nightly of CM11). But I did also remove the 'idc' file as suggested in this thread, by placing it back things seemed to work correctly (the arrow keys)
[/edit]
 
Last edited:

Artanis02

Senior Member
Nov 14, 2012
176
30
how to edit system files?
I cant do it even though i have root and es file explorer has access to root ;/
help

EDIT:
Got it :)

Is ADB process required? or can i just reboot ?
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 2
    Hi folks. I use JuiceSSH. In the current CM settings, it interprets the hardware alt key as an actual console alt. This is nice for changing windows in irssi (Alt+1, Alt+2, ...), but it's not useful for getting at the Fn keys for special characters. It would be nice to have Fn, Ctrl, and Alt, all working. Here's how to get this done:

    View this: hxxp://data.zx2c4.com/galaxy-relay-keyboard-map.jpg

    The file /system/usr/keylayout/sec_keypad.kl contains correlations of keycodes and keychars. It turns out JuiceSSH interprets ALT_LEFT as console alt, ALT_RIGHT as Fn, and CTRL_LEFT as console ctrl. So in that file, we want to remap ALT_LEFT to ALT_RIGHT, and then remap the MAIL and CHAT keys to CTRL_LEFT and ALT_LEFT respectively:

    Code:
    key 56    ALT_RIGHT         WAKE_DROPPED
    key 155  CTRL_LEFT          WAKE_DROPPED
    key 429  ALT_LEFT           WAKE_DROPPED
    key 217  META_LEFT          WAKE_DROPPED

    The full keycode file is available at hxxp://data.zx2c4.com/sec_keypad_modified.kl .

    Here's a command listing of how I enable this using adb:

    Code:
    zx2c4@thinkpad ~ $ adb shell
    shell@android:/ $ su
    root@android:/ # mount -o rw,remount /system
    root@android:/ # wget -O /system/usr/keylayout/sec_keypad.kl hxxp://data.zx2c4.com/sec_keypad_modified.kl
    root@android:/ # reboot

    In practice, this thus far works very well.

    Remember to change "hxxp" in this post; as a new member of XDA, I'm not allowed to post links.
    1
    I don't use JuiceSSH (but I'll definitely try it at some point if only for mosh), so I tried that with the built-in terminal app. By the way I don't know what version of CM 10.2 you're using, but here on the 20130909 nightly I found the kymaps in /system/usr/keylayout and not in /system/usr/keymap.

    I didn't remap ALT_LEFT, but did remap 155 to CTRL_LEFT and 429 to META_LEFT like you did. I also remapped 217 to ESCAPE which is very handy in vim. Here's the diff:

    --- sec_keypad.kl.orig 2013-09-12 17:55:28.434192677 -0600
    +++ sec_keypad.kl 2013-09-12 18:12:08.876521089 -0600
    @@ -81,3 +81,3 @@
    -key 155 ENVELOPE WAKE_DROPPED
    -key 429 CONTACTS WAKE_DROPPED
    -key 217 SEARCH WAKE_DROPPED
    +key 155 CTRL_LEFT WAKE_DROPPED
    +key 429 META_LEFT WAKE_DROPPED
    +key 217 ESCAPE WAKE_DROPPED

    The ESCAPE works but not the CTRL_LEFT and META_LEFT. The remapping does seem to work since the keys don't do any longer what they used to do. So I'm guessing it's the key compositing that doesn't work.

    I'll keep looking.