3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License (LGPL) as published by the Free Software Foundation.
7 Please refer to the COPYING file for more information.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 Copyright (c) 2004 Bruno T. C. de Oliveira
25 # include <ncursesw/ncurses.h>
33 static const char *keytable
[KEY_MAX
+1];
34 static int initialized
= 0;
36 static void keytable_init();
38 void rote_vt_keypress(RoteTerm
*rt
, int keycode
) {
39 char c
= (char) keycode
;
41 if (!initialized
) keytable_init();
43 if (keycode
>= 0 && keycode
< KEY_MAX
&& keytable
[keycode
])
44 rote_vt_write(rt
, keytable
[keycode
], strlen(keytable
[keycode
]));
46 rote_vt_write(rt
, &c
, 1); /* not special, just write it */
49 static void keytable_init() {
51 memset(keytable
, 0, KEY_MAX
+1 * sizeof(const char*));
53 keytable
['\n'] = "\r";
54 keytable
[KEY_UP
] = "\e[A";
55 keytable
[KEY_DOWN
] = "\e[B";
56 keytable
[KEY_RIGHT
] = "\e[C";
57 keytable
[KEY_LEFT
] = "\e[D";
58 keytable
[KEY_BACKSPACE
] = "\b";
59 keytable
[KEY_HOME
] = "\e[1~";
60 keytable
[KEY_IC
] = "\e[2~";
61 keytable
[KEY_DC
] = "\e[3~";
62 keytable
[KEY_END
] = "\e[4~";
63 keytable
[KEY_PPAGE
] = "\e[5~";
64 keytable
[KEY_NPAGE
] = "\e[6~";
65 keytable
[KEY_SUSPEND
] = "\x1A"; /* Ctrl+Z gets mapped to this */
66 keytable
[KEY_F(1)] = "\e[[A";
67 keytable
[KEY_F(2)] = "\e[[B";
68 keytable
[KEY_F(3)] = "\e[[C";
69 keytable
[KEY_F(4)] = "\e[[D";
70 keytable
[KEY_F(5)] = "\e[[E";
71 keytable
[KEY_F(6)] = "\e[17~";
72 keytable
[KEY_F(7)] = "\e[18~";
73 keytable
[KEY_F(8)] = "\e[19~";
74 keytable
[KEY_F(9)] = "\e[20~";
75 keytable
[KEY_F(10)] = "\e[21~";