1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Fix handling of Return and keypad Enter.

The recent rewriting in both the GTK and Windows keyboard handlers
left the keypad 'Enter' key in a bad state, when no override is
enabled that causes it to generate an escape sequence.

On Windows, a series of fallbacks was causing it to generate \r
regardless of configuration, whereas in Telnet mode it should default
to generating the special Telnet new-line sequence, and in response to
ESC[20h (enabling term->cr_lf_return) it should generate \r\n.

On GTK, it wasn't generating anything _at all_, and also, I can't see
any evidence that the GTK keyboard handler had ever remembered to
implement the cr_lf_return mode.

Now Keypad Enter in non-escape-sequence mode should behave just like
Return, on both platforms.
This commit is contained in:
Simon Tatham
2019-04-15 20:43:10 +01:00
parent 56198afb5c
commit 97a1021202
2 changed files with 60 additions and 18 deletions

View File

@ -4114,6 +4114,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
bool no_applic_k = conf_get_bool(conf, CONF_no_applic_k);
bool ctrlaltkeys = conf_get_bool(conf, CONF_ctrlaltkeys);
bool nethack_keypad = conf_get_bool(conf, CONF_nethack_keypad);
char keypad_key = '\0';
HKL kbd_layout = GetKeyboardLayout(0);
@ -4479,14 +4480,8 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
*p++ = 0x1E; /* Ctrl-~ == Ctrl-^ in xterm at least */
return p - output;
}
if (shift_state == 0 && wParam == VK_RETURN && term->cr_lf_return) {
*p++ = '\r';
*p++ = '\n';
return p - output;
}
switch (wParam) {
char keypad_key;
case VK_NUMPAD0: keypad_key = '0'; goto numeric_keypad;
case VK_NUMPAD1: keypad_key = '1'; goto numeric_keypad;
case VK_NUMPAD2: keypad_key = '2'; goto numeric_keypad;
@ -4520,7 +4515,8 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
(char *)p, term, keypad_key,
shift_state & 1, shift_state & 2);
if (!nchars) {
/* If we didn't get an escape sequence out of the
/*
* If we didn't get an escape sequence out of the
* numeric keypad key, then that must be because
* we're in Num Lock mode without application
* keypad enabled. In that situation we leave this
@ -4528,7 +4524,16 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
* below, which will translate it according to the
* appropriate keypad layout (e.g. so that what a
* Brit thinks of as keypad '.' can become ',' in
* the German layout). */
* the German layout).
*
* An exception is the keypad Return key: if we
* didn't get an escape sequence for that, we
* treat it like ordinary Return, taking into
* account Telnet special new line codes and
* config options.
*/
if (keypad_key == '\r')
goto ordinary_return_key;
break;
}
@ -4592,9 +4597,16 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
keypad_key = '\r';
goto numeric_keypad;
}
*p++ = 0x0D;
*p++ = 0;
return -2;
ordinary_return_key:
if (shift_state == 0 && term->cr_lf_return) {
*p++ = '\r';
*p++ = '\n';
return p - output;
} else {
*p++ = 0x0D;
*p++ = 0;
return -2;
}
}
}