2 these #defines are probably the ones most people will be interested in.
3 You can use these two #defines to hard code the key mappings --- just
4 uncomment the one you want. But only if you have trouble with learn
5 keys (which is unlikely).
8 /* KEY_BACKSPACE is the key learned in the learn keys menu : */
9 #define OUR_BACKSPACE_KEY KEY_BACKSPACE
10 /* ...otherwise ctrl-h : */
11 /* #define OUR_BACKSPACE_KEY XCTRL ('h') */
12 /* ...otherwise 127 or DEL in ascii : */
13 /* #define OUR_BACKSPACE_KEY 0177 */
15 /* KEY_DC is the key learned in the learn keys menu */
16 #define OUR_DELETE_KEY KEY_DC
17 /* ...otherwise ctrl-d : */
18 /* #define OUR_DELETE_KEY XCTRL ('d') */
19 /* ...otherwise 127 or DEL in ascii : */
20 /* #define OUR_DELETE_KEY 0177 */
24 This is #include'd into the function edit_translate_key in edit.c.
25 This sequence of code takes 'x_state' and 'x_key' and translates them
26 into either 'command' or 'char_for_insertion'. 'x_key' holds one of
27 KEY_NPAGE, KEY_HOME etc., and 'x_state' holds a bitwise inclusive OR of
28 CONTROL_PRESSED, ALT_PRESSED or SHIFT_PRESSED, although none may
30 'command' is one of the editor commands editcmddef.h.
32 Almost any C code can go into this file. The code below is an example
33 that may by appended or modified by the user.
36 /* look in this file for the list of commands : */
37 #include "editcmddef.h"
39 #define KEY_NUMLOCK ???
41 /* ordinary translations. (Some of this may be redundant.) Note that keys listed
42 first take priority when a key is assigned to more than one command */
43 static const long *key_map
;
44 static const long cooledit_key_map
[] =
45 {OUR_BACKSPACE_KEY
, CK_BackSpace
, OUR_DELETE_KEY
, CK_Delete
,
46 XCTRL ('d'), CK_Delete
, '\n', CK_Enter
,
47 KEY_PPAGE
, CK_Page_Up
, KEY_NPAGE
, CK_Page_Down
, KEY_LEFT
, CK_Left
,
48 KEY_RIGHT
, CK_Right
, KEY_UP
, CK_Up
, KEY_DOWN
, CK_Down
,
49 ALT ('\t'), CK_Return
, ALT ('\n'), CK_Return
,
50 KEY_HOME
, CK_Home
, KEY_END
, CK_End
, '\t', CK_Tab
,
51 XCTRL ('u'), CK_Undo
, KEY_IC
, CK_Toggle_Insert
,
52 XCTRL ('o'), CK_Shell
, KEY_F (3), CK_Mark
,
53 KEY_F (13), CK_Column_Mark
, KEY_F (5), CK_Copy
,
54 KEY_F (6), CK_Move
, KEY_F (8), CK_Remove
, KEY_F (12), CK_Save_As
,
55 KEY_F (2), CK_Save
, XCTRL ('n'), CK_New
,
56 XCTRL ('l'), CK_Refresh
, ESC_CHAR
, CK_Exit
, KEY_F (10), CK_Exit
,
57 KEY_F (11), /* edit user menu */ CK_User_Menu
,
58 KEY_F (19), /*C formatter */ CK_Pipe_Block (0),
59 XCTRL ('p'), /*spell check */ CK_Pipe_Block (1),
60 KEY_F (15), CK_Insert_File
,
61 XCTRL ('f'), CK_Save_Block
, KEY_F (1), CK_Help
,
62 ALT ('t'), CK_Sort
, ALT ('m'), CK_Mail
,
63 XCTRL ('z'), CK_Word_Left
, XCTRL ('x'), CK_Word_Right
,
64 KEY_F (4), CK_Replace
, KEY_F (7), CK_Find
, KEY_F (14), CK_Replace_Again
,
65 XCTRL ('h'), CK_BackSpace
, ALT ('l'), CK_Goto
, ALT ('L'), CK_Goto
,
66 XCTRL ('y'), CK_Delete_Line
,
67 XCTRL ('k'), CK_Delete_To_Line_End
,
68 KEY_F (17), CK_Find_Again
, ALT ('p'), CK_Paragraph_Format
,
69 ALT ('b'), CK_Match_Bracket
,
73 static long const emacs_key_map
[] =
74 {OUR_BACKSPACE_KEY
, CK_BackSpace
, OUR_DELETE_KEY
, CK_Delete
, '\n', CK_Enter
,
75 KEY_PPAGE
, CK_Page_Up
, KEY_NPAGE
, CK_Page_Down
, KEY_LEFT
, CK_Left
,
76 KEY_RIGHT
, CK_Right
, KEY_UP
, CK_Up
, KEY_DOWN
, CK_Down
,
77 ALT ('\t'), CK_Return
, ALT ('\n'), CK_Return
,
78 KEY_HOME
, CK_Home
, KEY_END
, CK_End
, '\t', CK_Tab
,
79 XCTRL ('u'), CK_Undo
, KEY_IC
, CK_Toggle_Insert
,
80 XCTRL ('o'), CK_Shell
, KEY_F (3), CK_Mark
, KEY_F (13), CK_Column_Mark
,
82 KEY_F (6), CK_Move
, KEY_F (8), CK_Remove
, KEY_F (12), CK_Save_As
,
83 KEY_F (2), CK_Save
, ALT ('p'), CK_Paragraph_Format
,
87 XCTRL ('a'), CK_Home
, XCTRL ('e'), CK_End
,
88 XCTRL ('b'), CK_Left
, XCTRL ('f'), CK_Right
,
89 XCTRL ('n'), CK_Down
, XCTRL ('p'), CK_Up
,
90 XCTRL ('d'), CK_Delete
,
91 XCTRL ('v'), CK_Page_Down
, ALT ('v'), CK_Page_Up
,
93 XCTRL ('k'), CK_Delete_To_Line_End
,
96 ALT ('b'), CK_Word_Left
, ALT ('f'), CK_Word_Right
,
98 XCTRL ('y'), CK_XPaste
,
101 XCTRL ('l'), CK_Refresh
, ESC_CHAR
, CK_Exit
, KEY_F (10), CK_Exit
,
102 KEY_F (11), /* edit user menu */ CK_User_Menu
,
103 KEY_F (19), /*C formatter */ CK_Pipe_Block (0),
104 ALT ('$'), /*spell check */ CK_Pipe_Block (1),
105 KEY_F (15), CK_Insert_File
,
108 KEY_F (4), CK_Replace
, KEY_F (7), CK_Find
, KEY_F (14), CK_Replace_Again
,
109 XCTRL ('h'), CK_BackSpace
, ALT ('l'), CK_Goto
, ALT ('L'), CK_Goto
,
110 KEY_F (17), CK_Find_Again
,
111 ALT ('<'), CK_Beginning_Of_Text
,
112 ALT ('>'), CK_End_Of_Text
,
117 static long const key_pad_map
[10] =
118 {XCTRL ('o'), KEY_END
, KEY_DOWN
, KEY_NPAGE
, KEY_LEFT
,
119 KEY_DOWN
, KEY_RIGHT
, KEY_HOME
, KEY_UP
, KEY_PPAGE
};
122 #define DEFAULT_NUM_LOCK 0
124 static int num_lock
= DEFAULT_NUM_LOCK
;
127 switch (edit_key_emulation
) {
128 case EDIT_KEY_EMULATION_NORMAL
:
129 key_map
= cooledit_key_map
;
131 case EDIT_KEY_EMULATION_EMACS
:
132 key_map
= emacs_key_map
;
133 if (x_key
== XCTRL ('x')) {
135 ext_key
= edit_raw_key_query (" Ctrl-X ", _(" Emacs key: "), 0);
147 command
= CK_Macro (edit_raw_key_query (_(" Execute Macro "), _(" Press macro hotkey: "), 1));
148 if (command
== CK_Macro (0))
158 if (x_key
== XCTRL('t')) {
159 do_select_codepage();
161 edit
->force
= REDRAW_COMPLETELY
;
162 command
= CK_Refresh
;
167 if (x_key
== XCTRL ('q')) {
168 char_for_insertion
= edit_raw_key_query (_(" Insert Literal "), _(" Press any key: "), 0);
171 if (x_key
== XCTRL ('a') && edit_key_emulation
!= EDIT_KEY_EMULATION_EMACS
) {
172 command
= CK_Macro (edit_raw_key_query (_(" Execute Macro "), _(" Press macro hotkey: "), 1));
173 if (command
== CK_Macro (0))
177 /* edit is a pointer to the widget */
179 if (x_key
== XCTRL ('r')) {
180 command
= edit
->macro_i
< 0 ? CK_Begin_Record_Macro
: CK_End_Record_Macro
;
183 /* if (x_key == KEY_NUMLOCK) {
184 num_lock = 1 - num_lock;
189 /* first translate the key-pad */
191 if (x_key
>= '0' && x_key
<= '9') {
192 x_key
= key_pad_map
[x_key
- '0'];
198 if ((x_state
& SHIFT_PRESSED
) && (x_state
& CONTROL_PRESSED
)) {
201 command
= CK_Beginning_Of_Text_Highlight
;
204 command
= CK_End_Of_Text_Highlight
;
207 command
= CK_Word_Left_Highlight
;
210 command
= CK_Word_Right_Highlight
;
213 command
= CK_Scroll_Up_Highlight
;
216 command
= CK_Scroll_Down_Highlight
;
220 if ((x_state
& SHIFT_PRESSED
) && !(x_state
& CONTROL_PRESSED
)) {
223 command
= CK_Page_Up_Highlight
;
226 command
= CK_Page_Down_Highlight
;
229 command
= CK_Left_Highlight
;
232 command
= CK_Right_Highlight
;
235 command
= CK_Up_Highlight
;
238 command
= CK_Down_Highlight
;
241 command
= CK_Home_Highlight
;
244 command
= CK_End_Highlight
;
254 /* things that need a control key */
255 if (x_state
& CONTROL_PRESSED
) {
258 command
= CK_Save_As
;
261 command
= CK_Replace_Again
;
264 command
= CK_Find_Again
;
270 command
= CK_Beginning_Of_Text
;
273 command
= CK_End_Of_Text
;
276 command
= CK_Scroll_Up
;
279 command
= CK_Scroll_Down
;
282 command
= CK_Word_Left
;
285 command
= CK_Word_Right
;
295 /* an ordinary insertable character */
298 if (x_key
< 256 && is_printable (x_key
)) {
299 char_for_insertion
= x_key
;
301 if (x_key
< 256 && is_printable (conv_input
[x_key
])) {
302 char_for_insertion
= conv_input
[x_key
];
309 while (key_map
[i
] != x_key
&& (key_map
[i
] || key_map
[i
+ 1]))
311 command
= key_map
[i
+ 1];
315 /* Function still not found for this key, so try macro's */
316 /* This allows the same macro to be
317 enabled by either eg "ALT('f')" or "XCTRL('f')" or "XCTRL('a'), 'f'" */
319 /* key.h: #define ALT(x) (0x200 | (x)) */
320 if (x_key
& ALT (0)) { /* is an alt key ? */
321 command
= CK_Macro (x_key
- ALT (0));
324 /* key.h: #define XCTRL(x) ((x) & 31) */
325 if (x_key
< ' ') { /* is a ctrl key ? */
326 command
= CK_Macro (x_key
);