From 195b2c09debf8f89c76767142bb2ea8d42c6732a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 8 Jan 2017 09:51:14 +0530 Subject: [PATCH] Send special CSI sequences for Ctrl+arrow keys Mimics behavior of xterm. Fixes #15 --- kitty/keys.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kitty/keys.py b/kitty/keys.py index 0b3e48ae1..363eda813 100644 --- a/kitty/keys.py +++ b/kitty/keys.py @@ -35,7 +35,13 @@ SHIFTED_KEYS = { defines.GLFW_KEY_RIGHT: key_as_bytes('kRIT'), } -control_codes = {k: 1 + i for i, k in enumerate(range(defines.GLFW_KEY_A, defines.GLFW_KEY_RIGHT_BRACKET + 1))} +control_codes = {k: (1 + i,) for i, k in enumerate(range(defines.GLFW_KEY_A, defines.GLFW_KEY_RIGHT_BRACKET + 1))} +control_codes[defines.GLFW_KEY_UP] = bytearray(key_as_bytes('cuu1').replace(b'[', b'[1;5')) +control_codes[defines.GLFW_KEY_DOWN] = bytearray(key_as_bytes('cud1').replace(b'[', b'[1;5')) +control_codes[defines.GLFW_KEY_LEFT] = bytearray(key_as_bytes('cub1').replace(b'[', b'[1;5')) +control_codes[defines.GLFW_KEY_RIGHT] = bytearray(key_as_bytes('cuf1').replace(b'[', b'[1;5')) +control_codes[defines.GLFW_KEY_PAGE_UP] = bytearray(key_as_bytes('kpp').replace(b'~', b';5~')) +control_codes[defines.GLFW_KEY_PAGE_DOWN] = bytearray(key_as_bytes('knp').replace(b'~', b';5~')) alt_codes = {k: (0x1b, k) for i, k in enumerate(range(defines.GLFW_KEY_SPACE, defines.GLFW_KEY_RIGHT_BRACKET + 1))} @@ -43,7 +49,7 @@ def interpret_key_event(key, scancode, mods): data = bytearray() if mods == defines.GLFW_MOD_CONTROL and key in control_codes: # Map Ctrl-key to ascii control code - data.append(control_codes[key]) + data.extend(control_codes[key]) elif mods == defines.GLFW_MOD_ALT and key in alt_codes: # Map Alt+key to Esc-key data.extend(alt_codes[key])