1 /* Keyboard support routines.
4 20. April 97: Alexander Dong (ado)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #error This file is for OS/2 systems.
32 #define INCL_DOSERRORS
36 #include "../src/mouse.h"
37 #include "../src/global.h"
38 #include "../src/main.h"
39 #include "../src/key.h"
40 #include "../vfs/vfs.h"
41 #include "../src/tty.h"
43 /* Code to read keystrokes in a separate thread */
45 typedef struct kbdcodes
{
48 USHORT shift
; /* .ado: change for mc */
51 /* Global variables */
53 /* HANDLE hConsoleInput;
54 DWORD dwSaved_ControlState; */
55 Gpm_Event evSaved_Event
;
57 /* Unused variables */
58 int double_click_speed
; /* they are here to keep linker happy */
60 int use_8th_bit_as_meta
= 0;
62 static int VKtoCurses (int vkcode
);
64 /* -------------------------------------------------------------- */
66 Return from SLANG: KeyCode: 0xaaaabbcc
70 cc = ASCII-code (if available)
72 if no flags (CTRL and ALT) is set, cc will be returned.
73 If CTRL is pressed, cc is already the XCTRL(code).
75 0xE0: The scan code will be used for the following keys:
76 Insert: 0x52, DEL: 0x53,
77 Page_Up: 0x49, Page_Down: 0x51,
78 Pos1: 0x47, Ende: 0x4F,
80 Left: 0x4B, Right: 0x4D,
82 0x00: The function keys are defined as:
83 F1: 3b00, F2: 3c00 ... F10: 4400, F11: 8500, F12: 8600.
85 ALT(F1): 6800, 6900,... ALT(F10): 7100, ALT(F11): 8b00
88 Mapping for ALT(key_code):
89 For Mapping with normal keys, only the scan code can be
90 used. (see struct ALT_table)
93 ENTER (number block): 0xaaaaE00D
94 + (number block): 0xaaaa4E2B Normal: 1B2B
95 - (number block): 0xaaaa4A2D Normal: 352D
96 * (number block): 0xaaaa372A Normal: 1B2A
97 / (number block): 0xaaaaE02F
99 /* -------------------------------------------------------------- */
100 #define RIGHT_SHIFT_PRESSED 1
101 #define LEFT_SHIFT_PRESSED 2
102 #define CTRL_PRESSED 4
103 #define ALT_PRESSED 8
104 #define SCROLL_LOCK_MODE 16
105 #define NUM_LOCK_MODE 32
106 #define CAPS_LOCK_MODE 64
107 #define INSERT_MODE 128
108 #define LEFT_CTRL_PRESSED 256
109 #define LEFT_ALT_PRESSED 512
110 #define RIGHT_CTRL_PRESSED 1024
111 #define RIGHT_ALT_PRESSED 2048
112 #define SCROLL_LOCK_PRESSED 4096
113 #define NUM_LOCK_PRESSED 8192
114 #define CAPS_LOCK_PRESSED 16384
116 /* -------------------------------------------------------------- */
171 { ALT(KEY_F(1)), 0x68 },
172 { ALT(KEY_F(2)), 0x69 },
173 { ALT(KEY_F(3)), 0x6A },
174 { ALT(KEY_F(4)), 0x6B },
175 { ALT(KEY_F(5)), 0x6C },
176 { ALT(KEY_F(6)), 0x6D },
177 { ALT(KEY_F(7)), 0x6E },
178 { ALT(KEY_F(8)), 0x6F },
179 { ALT(KEY_F(9)), 0x70 },
180 { ALT(KEY_F(10)), 0x71 },
181 { ALT(KEY_F(11)), 0x8B },
182 { ALT(KEY_F(12)), 0x8C },
205 /* init_key -- to make linker happy */
212 /* The maximum sequence length (32 + null terminator) */
213 static int seq_buffer
[33];
214 static int *seq_append
= 0;
216 static int push_char (int c
)
219 seq_append
= seq_buffer
;
221 if (seq_append
== &(seq_buffer
[sizeof (seq_buffer
)-2]))
228 int get_key_code (int no_delay
)
233 /* Check if any input pending, otherwise return */
234 nodelay (stdscr
, TRUE
);
235 inp_ch
= SLang_input_pending(0);
242 return (VKtoCurses(inp_ch
));
246 inp_ch
= SLang_getkey();
248 inp_ch
= (SLang_getkey() << 8);
249 if (inp_ch
) return (VKtoCurses(inp_ch
));
254 static int VKtoCurses (int a_vkc
)
265 fsState
= (a_vkc
& 0xFFFF0000) >> 16;
266 fsState
&= (~INSERT_MODE
); /* Ignore Insertion mode */
268 scanCode
= (char) ((a_vkc
& 0x0000FFFF) >> 8);
269 asciiCode
= (char) (a_vkc
& 0x000000FF);
271 ctrlState
= (fsState
& CTRL_PRESSED
);
272 altState
= (fsState
& ALT_PRESSED
);
278 rtnCode
= XCTRL(asciiCode
);
283 * rtnCode = ALT(asciiCode);
285 * With German keyboards, the Values between 7B -> 7D
286 * and 5b, 5d, 40, fd, fc and e6 are only reachable with the AltGr
287 * key. If such a combination is used, asciiCode will not be zero.
288 * With the normal ALT key, the asciiCode will always be zero.
295 /* Scan Movement codes */
296 if (asciiCode
== 0) {
297 /* Replace key code with that in table */
298 for (i
=0; movement
[i
].vkcode
!= 0 || movement
[i
].key_code
!= 0; i
++)
299 if (scanCode
== movement
[i
].vkcode
)
300 return (movement
[i
].key_code
);
303 if (asciiCode
== 0) {
304 /* Function-key detected */
305 for (i
=0; fkt_table
[i
].vkcode
!= 0 || fkt_table
[i
].key_code
!= 0; i
++)
306 if (scanCode
== fkt_table
[i
].vkcode
)
307 return (fkt_table
[i
].key_code
);
309 /* if (altState) */ {
310 for (i
=0; ALT_table
[i
].vkcode
!= 0 || ALT_table
[i
].key_code
!= 0; i
++)
311 if (scanCode
== ALT_table
[i
].vkcode
)
312 return (ALT_table
[i
].key_code
);
316 if (asciiCode
== 0x0d) {
324 static int getch_with_delay (void)
329 /* Try to get a character */
330 c
= get_key_code (0);
334 /* Success -> return the character */
338 int get_event (Gpm_Event
*event
, int redo_event
, int block
)
341 static int dirty
= 3;
343 if ((dirty
== 1) || is_idle ()){
350 vfs_timeout_handler ();
352 c
= block
? getch_with_delay () : get_key_code (1);
354 /* Code is 0, so this is a Control key or mouse event */
355 *event
= evSaved_Event
;
356 return EV_NONE
; /* FIXME: when should we return EV_MOUSE ? */
362 /* Returns a key press, mouse events are discarded */
368 while ((key
= get_event (&ev
, 0, 1)) == 0)
375 is_idle - A function to check if we're idle.
376 It checks for any waiting event (that can be a Key, Mouse event,
377 and other internal events like focus or menu)
396 /* void functions for UNIX copatibility */
397 void define_sequence (int code
, char* vkcode
, int action
) {}
398 void channels_up() {}
399 void channels_down() {}
400 void init_key_input_fd (void) {}
401 void numeric_keypad_mode (void) {}
402 void application_keypad_mode (void) {}
404 /* mouse is not yet supported, sorry */
405 void init_mouse (void) {}
406 void shut_mouse (void) {}