1 /* Copyright (c) 1992, 1999, 2001, 2002 John E. Davis
2 * This file is part of the S-Lang library.
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Perl Artistic License.
13 unsigned int SLang_Input_Buffer_Len
= 0;
14 unsigned char SLang_Input_Buffer
[SL_MAX_INPUT_BUFFER_LEN
];
16 int SLang_Abort_Char
= 7;
17 int SLang_Ignore_User_Abort
= 0;
19 /* This has the effect of mapping all characters in the range 128-169 to
23 unsigned int SLang_getkey (void)
28 if (SLang_Input_Buffer_Len
)
30 ch
= (unsigned int) *SLang_Input_Buffer
;
31 SLang_Input_Buffer_Len
--;
32 imax
= SLang_Input_Buffer_Len
;
34 SLMEMCPY ((char *) SLang_Input_Buffer
,
35 (char *) (SLang_Input_Buffer
+ 1), imax
);
37 else if (SLANG_GETKEY_ERROR
== (ch
= _SLsys_getkey ())) return ch
;
39 #if _SLANG_MAP_VTXXX_8BIT
40 # if !defined(IBMPC_SYSTEM)
44 i
= (unsigned char) (ch
& 0x7F);
57 int SLang_ungetkey_string (unsigned char *s
, unsigned int n
)
59 register unsigned char *bmax
, *b
, *b1
;
60 if (SLang_Input_Buffer_Len
+ n
+ 3 > SL_MAX_INPUT_BUFFER_LEN
)
63 b
= SLang_Input_Buffer
;
64 bmax
= (b
- 1) + SLang_Input_Buffer_Len
;
66 while (bmax
>= b
) *b1
-- = *bmax
--;
68 while (b
< bmax
) *b
++ = *s
++;
69 SLang_Input_Buffer_Len
+= n
;
73 int SLang_buffer_keystring (unsigned char *s
, unsigned int n
)
76 if (n
+ SLang_Input_Buffer_Len
+ 3 > SL_MAX_INPUT_BUFFER_LEN
) return -1;
78 SLMEMCPY ((char *) SLang_Input_Buffer
+ SLang_Input_Buffer_Len
,
80 SLang_Input_Buffer_Len
+= n
;
84 int SLang_ungetkey (unsigned char ch
)
86 return SLang_ungetkey_string(&ch
, 1);
89 int SLang_input_pending (int tsecs
)
93 if (SLang_Input_Buffer_Len
) return (int) SLang_Input_Buffer_Len
;
95 n
= _SLsys_input_pending (tsecs
);
99 c
= (unsigned char) SLang_getkey ();
100 SLang_ungetkey_string (&c
, 1);
105 void SLang_flush_input (void)
107 int quit
= SLKeyBoard_Quit
;
109 SLang_Input_Buffer_Len
= 0;
111 while (_SLsys_input_pending (0) > 0)
113 (void) _SLsys_getkey ();
114 /* Set this to 0 because _SLsys_getkey may stuff keyboard buffer if
115 * key sends key sequence (OS/2, DOS, maybe VMS).
117 SLang_Input_Buffer_Len
= 0;
119 SLKeyBoard_Quit
= quit
;
123 static int Map_To_ANSI
;
124 int SLgetkey_map_to_ansi (int enable
)
126 Map_To_ANSI
= enable
;
130 static int convert_scancode (unsigned int scan
,
133 unsigned int *ret_key
)
135 unsigned char buf
[16];
140 shift
&= (_SLTT_KEY_ALT
|_SLTT_KEY_SHIFT
|_SLTT_KEY_CTRL
);
143 if (_SLTT_KEY_ALT
== shift
)
155 if (shift
== _SLTT_KEY_CTRL
)
157 else if (shift
== _SLTT_KEY_SHIFT
)
162 /* These mappings correspond to what rxvt produces under Linux */
168 case 0x47: /* home */
175 case 0x49: /* PgUp */
178 case 0x4B: /* Left */
182 case 0x4D: /* Right */
189 case 0x50: /* Down */
193 case 0x51: /* PgDn */
196 case 0x52: /* Insert */
199 case 0x53: /* Delete */
261 if (is_arrow
&& shift
)
263 if (shift
== _SLTT_KEY_CTRL
)
272 (void) SLang_buffer_keystring (buf
+ 1, (unsigned int) (b
- (buf
+ 1)));
277 (void) SLang_buffer_keystring (buf
, (unsigned int) (b
- buf
));
282 unsigned int _SLpc_convert_scancode (unsigned int scan
,
286 unsigned char buf
[16];
290 if (0 == convert_scancode (scan
, shift
, getkey
, &scan
))
296 buf
[0] = scan
& 0xFF;
297 SLang_buffer_keystring (buf
, 1);
298 return (scan
>> 8) & 0xFF;
300 buf
[0] = (scan
>> 8) & 0xFF;
301 buf
[1] = scan
& 0xFF;
302 (void) SLang_buffer_keystring (buf
, 2);