how to map keypad enter differently?

68 views
Skip to first unread message

warren zaccone

unread,
Nov 17, 2017, 12:55:40 PM11/17/17
to chromium-hterm
my application requires keypad-enter to map differently than the return key.    I see comments in the code mapping both keys to 13.   I need key-pad enter to send 10 and return to be 13..  where is the appropriate place to change this?   thanks.

Mike Frysinger

unread,
Nov 18, 2017, 2:05:35 AM11/18/17
to warren zaccone, chromium-hterm
what OS are you using ?  you need to make sure it differentiates between them.  if it doesn't, hterm can't do anything about it.
-mike

On Fri, Nov 17, 2017 at 12:55 PM, warren zaccone <vosdevel...@gmail.com> wrote:
my application requires keypad-enter to map differently than the return key.    I see comments in the code mapping both keys to 13.   I need key-pad enter to send 10 and return to be 13..  where is the appropriate place to change this?   thanks.

--
You received this message because you are subscribed to the Google Groups "chromium-hterm" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-hterm/dd3d2eb9-2659-4b8e-84b6-b46bb6b9dcfb%40chromium.org.

warren zaccone

unread,
Nov 18, 2017, 7:18:15 PM11/18/17
to chromium-hterm
I should elaborate . I am developing a Javascript based telnet and ssh client and integrating hterm as the terminal into my code. Terminal is presented in Browser (chrome, Firefox. Edge) on ms windows who communicates with a separate daemon on a Linux web server who acts as a proxy with a minicomputer vterm terminal driver. My project is to replace an old Java applet on a internal corporate web site with Javascript . I decided to use hterm with the plan to go thru an ssh tunnel maybe using secure shell once I get telnet working, so far telnet looks great I am mapping the keystrokes to sequences that the backend driver recognizes and sending them via web sockets on to a web sockets server process who does the handshaking and forwards them on to a vterm driver on a minicomputer. The terminal screen comes up nice, output looks good. I am mapping keys in my code and the keys work except for keypad enter and controlbreak, which I am working on now, I was studying in hterm where the key event is trapped to see what I need to change to recognize key pad enter independently of return — I don’t want keypad enter to do a carriage return at all . I need to map it to the sequences our backend app recognizes. I just need the two keys: return and enter to give me back something different for each other so I can map the keys and I will take it from there. Thanks Warren

Mike Frysinger

unread,
Nov 18, 2017, 9:47:26 PM11/18/17
to warren zaccone, chromium-hterm
so have you verified that the browser can actually differentiate ?

visit http://unixpapa.com/js/testkey.html and try hitting the two different keys.  if they show up differently, then it shouldn't be a problem problem mapping them differently in hterm.  if that page shows the same output for the diff keys, there's nothing hterm can do about it.
-mike

On Sat, Nov 18, 2017 at 7:18 PM, warren zaccone <vosdevel...@gmail.com> wrote:
I should elaborate . I am developing a Javascript based telnet and ssh client and integrating hterm as the terminal into my code.  Terminal is presented in Browser  (chrome, Firefox. Edge) on ms windows who communicates  with a separate daemon on a Linux web server who acts as a proxy with a minicomputer vterm terminal driver. My project is to replace an old Java applet on a internal corporate web site  with Javascript . I decided to use hterm with the plan to go thru an ssh tunnel maybe using secure shell once I get telnet working,  so far telnet looks great I am mapping the keystrokes to sequences that the backend driver recognizes and sending them via web sockets on to a web sockets server process who does the handshaking and forwards them on to a  vterm driver on a minicomputer. The terminal screen comes up nice, output looks good. I am mapping keys in my code  and the keys work except for keypad enter and controlbreak,  which I am working on now,  I was studying in hterm where the key event is trapped to see what I need to change to recognize key pad enter independently of return — I don’t want keypad enter to do a carriage return at all . I need to  map it to the sequences  our backend app recognizes.  I  just need the two keys: return and enter to give me back something different for each other so I can map the keys and I will take it from there.   Thanks Warren
--
You received this message because you are subscribed to the Google Groups "chromium-hterm" group.

warren zaccone

unread,
Nov 20, 2017, 9:14:56 AM11/20/17
to chromium-hterm
thanks for that tool.   both keys return  13  so I have to use a different approach for keypad enter. I  was able to define shift-enter for the functionality.

 t.keyboard.bindings.addBinding('Shift-ENTER', function() {
       return '\x1bOM';
       });

The other key I need to map is control-break. It returns a 3 using testkey  but triggers an error in my app from hterm.   can I add this definition?

No definition for keyCode: 3                   hterm_all.js:6472:5


Warren
        

Mike Frysinger

unread,
Nov 20, 2017, 10:50:16 AM11/20/17
to warren zaccone, chromium-hterm
that's not an error, that's a warning, and it doesn't matter -- just bind the numerical value directly and it should work fine

--
You received this message because you are subscribed to the Google Groups "chromium-hterm" group.

warren zaccone

unread,
Dec 6, 2017, 2:21:02 PM12/6/17
to chromium-hterm, vosdevel...@gmail.com
Interestingly I found that browser does know that hit  keys on the keypad. the code attribute of the event is different. 
 It seems to know about all of the keypad keys.  My application has special hot keys using the keypad so I need to override the keypad keys.  I can deal with keypad enter
with shift-return, but I'd really like to trap the other keycodes differently. Is  it possible since a different keycode is returned for example for keypad minus
  for me to bind that differently?    109 vs 189.  hterm returns me a minus both cases. I want to change that for keypad minus and the other keypad keys.

sample code (same results in Firefox and Chrome)

 document.addEventListener("keydown", functionKeyHandler_c, false);

function functionKeyHandler_c ( oEvt ) {

   console.log ("***************** KEY PRESSED ***********************");
    console.log ("keycode= " + oEvt.keyCode);
    console.log ("key= " + oEvt.key);
    console.log ("code= " + oEvt.code);
}
console in both firefox and chrome shows the following when hit return and then keypad enter
 
***************** KEY PRESSED ***********************
keycode= 13
key= Enter
code= Enter
***************** KEY PRESSED ***********************
keycode= 13
key= Enter
code= NumpadEnter  <<<

Pressing the numeric keys on the keypad and then the regular digit keys also yields different results.  I


press keypad minus key

 ***************** KEY PRESSED ***********************
keycode= 109  <<<
key= -
code= NumpadSubtract  <<<

pressed regular minus key

***************** KEY PRESSED ***********************
keycode= 189  <<<
key= -
code= Minus   <<<
Warren

Mike Frysinger

unread,
Dec 6, 2017, 4:32:56 PM12/6/17
to chromium-hterm
have you followed the documentation for creating keyboard mappings via the keycode ?
https://chromium.googlesource.com/apps/libapps/+/master/hterm/doc/KeyboardBindings.md

it would help if you described in detail what you actually tried and what didn't work.
-mike

warren zaccone

unread,
Dec 7, 2017, 9:09:40 AM12/7/17
to chromium-hterm
I think narrowed this down.  I am able to successfully bind some of the keypad keys

// override keypad add
    t.keyboard.bindings.addBinding("107", function() {  
      return '\x1bkp+';
      });

what doesn't work are the keys that give me the warning message  No Definition found for keyCode: 12
an example is the clear key.   when num lock is off, pressing the 5 key on the keypad is supposed to send a clear which our application recognizes.
Using  http://unixpapa.com/js/testkey.html  I press the 5 key on the keypad with numlock off and the keyCode is 12

I get the warning message:  No Definition found for Keycode:12   however even though its just a warning, it is not firing VTKeyStroke

my handler (shown below)  is invoked for all the other keys but not keypad 5 and I get the warning.

   io.onVTKeystroke = function(str) {
      handleKey(str);
      };

I added a binding for it

// override keypad clear ( keypad 5) 
    t.keyboard.bindings.addBinding("12", function() {  
      return '\x1bkpclear';
      });


looking at the code, the  warning message is displayed if the key is not found in the keydefs array.

hterm.Keyboard.prototype.onKeyDown_ = function(e) {
  if (e.keyCode == 18)
    this.altKeyPressed = this.altKeyPressed | (1 << (e.location - 1));

  if (e.keyCode == 27)
    this.preventChromeAppNonCtrlShiftDefault_(e);

  var keyDef = this.keyMap.keyDefs[e.keyCode];
  if (!keyDef) {
    console.warn('No definition for keyCode: ' + e.keyCode);
    return;
  }

I noticed a return statement after the warning.   Since the keydef information is referenced afterward I can see why it returns, so I figured I needed to add
12 to the keydefs array which is where I am now and that's my only question.  I having a little trouble getting there from the doc file. I read it several times.

I need to add           [12, '[KP5]', DEFAULT, DEFAULT, DEFAULT, DEFAULT] );   and possibly other keyhs  to keydefs.

how to do that is my only question  

thanks,
Warren

warren zaccone

unread,
Dec 8, 2017, 11:49:23 AM12/8/17
to chromium-hterm
 - I figured this out and got all my keys working (yeah) from reading thru the code.   for example:  to define eypad 5 (with num lock off) I had to put in the following in my code:

    var DEFAULT = hterm.Keyboard.KeyActions.DEFAULT;

    t.keyboard.keyMap.addKeyDefs([12, '[CLEAR]', DEFAULT, DEFAULT, DEFAULT, DEFAULT]);

Mike Frysinger

unread,
Dec 12, 2017, 12:15:27 PM12/12/17
to warren zaccone, chromium-hterm
hmm, pretty sure it wasn't the intention to block custom keybindings for unknown keys.  this should fix things so you don't have to explicitly call addKeyDefs yourself:

as for the keypad, we document this in the keymap file:
    // With numlock off, the keypad generates the same key codes as the arrows  
    // and 'block of six' for some keys, and null key codes for the rest.
in this scenario, KP5 is the only one that isn't mapped.  we could probably provide a definition similar to what you showed for the [CLEAR] key as that seems to be the default mapping (at least under Linux).  it would also match for Apple keyboards that replace NumLock with Clear.

if numlock is on, then hterm sees the keys you'd expect -- 5 is 5, 6 is 6, etc...
-mike

warren zaccone

unread,
Dec 13, 2017, 11:03:34 AM12/13/17
to chromium-hterm, vosdevel...@gmail.com
thank you.    I appreciate adding the clear key.    

Revisiting keypad Enter  I noticed that both firefox and chrome return a unique key description in the e.code field.   return has e.code == "Enter"   whereas keypad enter has e.code == "NumpadEnter".  

 Given that I was able to add the following. 

  if ((e.keyCode == 13) && (e.code == "NumpadEnter")) {
  myKeyCode = 10;   
}


Here is the change in context: 



hterm.Keyboard.prototype.onKeyDown_ = function(e) {
  if (e.keyCode == 18)
    this.altKeyPressed = this.altKeyPressed | (1 << (e.location - 1));

var myKeyCode = e.keyCode;  
  
  if ((e.keyCode == 13) && (e.code == "NumpadEnter")) {
  myKeyCode = 10;   
}

  var keyDef = this.keyMap.keyDefs[myKeyCode];
  if (!keyDef) {
    console.warn('No definition for keyCode: ' + myKeyCode);
    return;
  }

Then I was able to add 10 to keydefs to I can bind it (I realize with your change I don't need to do this part)  

    t.keyboard.keyMap.addKeyDefs([10, '[KPENTER]', DEFAULT, DEFAULT, DEFAULT, DEFAULT]);


t.keyboard.bindings.addBinding ("10"... )

Since code="NumpadEnter"  in Firefox and Chrome, I got keypad enter to work.  (don't want to have to retrain users ).     I am still going to bind shift-enter as a fallback.  

Mike Frysinger

unread,
Dec 13, 2017, 1:15:45 PM12/13/17
to warren zaccone, chromium-hterm
thanks for finding this.  i agree we should allow users to bind based on KeyboardEvent.code.  it might even make our lives easier wrt parsing ...

since this is a bit more than i want to bite off right now, i moved to https://crbug.com/794617 so you can star to follow progress.
-mike

Mike Frysinger

unread,
Dec 13, 2017, 2:51:39 PM12/13/17
to warren zaccone, chromium-hterm
all the other changes have landed now and will be in the next release of hterm/secure shell.  thanks for the feedback.
-mike
Reply all
Reply to author
Forward
0 new messages