1 /* Keyboard support routines.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 Have trouble with non-US keyboards, "Alt-gr"+keys (API tells CTRL-ALT is pressed)
23 #error "This file is for Win32 systems only"
27 #include "../src/global.h"
28 #include "../src/mouse.h"
29 #include "../src/main.h"
30 #include "../src/key.h"
31 #include "../vfs/vfs.h"
32 #include "../src/tty.h"
35 /* Global variables */
38 DWORD dwSaved_ControlState
;
39 Gpm_Event evSaved_Event
;
41 /* Unused variables */
42 int double_click_speed
; /* they are here to keep linker happy */
44 int use_8th_bit_as_meta
= 0;
60 { KEY_F(10), VK_F10
},
61 { KEY_F(11), VK_F11
},
62 { KEY_F(12), VK_F12
},
63 { KEY_F(13), VK_F13
},
64 { KEY_F(14), VK_F14
},
65 { KEY_F(15), VK_F15
},
66 { KEY_F(16), VK_F16
},
67 { KEY_F(17), VK_F17
},
68 { KEY_F(18), VK_F18
},
69 { KEY_F(19), VK_F19
},
70 { KEY_F(20), VK_F20
},
71 { KEY_IC
, VK_INSERT
},
72 { KEY_DC
, VK_DELETE
},
73 { KEY_BACKSPACE
, VK_BACK
},
75 { KEY_PPAGE
, VK_PRIOR
},
76 { KEY_NPAGE
, VK_NEXT
},
77 { KEY_LEFT
, VK_LEFT
},
78 { KEY_RIGHT
, VK_RIGHT
},
80 { KEY_DOWN
, VK_DOWN
},
81 { KEY_HOME
, VK_HOME
},
84 { ALT('*'), VK_MULTIPLY
},
86 { ALT('-'), VK_SUBTRACT
},
87 { ALT('\t'), VK_PAUSE
}, /* Added to make Complete work press Pause */
89 { ESC_CHAR
, VK_ESCAPE
},
94 /* init_key - Called in main.c to initialize ourselves
95 Get handle to console input
99 win32APICALL_HANDLE (hConsoleInput
, GetStdHandle (STD_INPUT_HANDLE
));
104 if(dwSaved_ControlState
& RIGHT_ALT_PRESSED
) return 0;
105 /* The line above fixes the BUG with the AltGr Keys*/
106 return dwSaved_ControlState
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
);
111 return dwSaved_ControlState
& SHIFT_PRESSED
;
116 return dwSaved_ControlState
& (/* RIGHT_ALT_PRESSED |*/ LEFT_ALT_PRESSED
);
119 static int VKtoCurses (int a_vkc
)
123 for (i
= 0; fkt_table
[i
].vkcode
!= 0; i
++)
124 if (a_vkc
== fkt_table
[i
].vkcode
) {
125 return fkt_table
[i
].key_code
;
130 static int translate_key_code(int asc
, int scan
)
134 case 106: /* KP_MULT*/
136 case 107: /* KP_PLUS*/
138 case 109: /* KP_MINUS*/
141 c
= VKtoCurses (scan
);
146 if (!asc
|| asc
=='\t' )
148 if (shift_pressed() && (c
>= KEY_F(1)) && (c
<= KEY_F(10)))
150 if (alt_pressed() && (c
>= KEY_F(1)) && (c
<= KEY_F(2)))
152 if (alt_pressed() && (c
== KEY_F(7)))
155 if(ctrl_pressed())c
= ALT('\t');
169 int get_key_code (int no_delay
)
171 INPUT_RECORD ir
; /* Input record */
172 DWORD dw
; /* number of records actually read */
176 /* Check if any input pending, otherwise return */
177 nodelay (stdscr
, TRUE
);
178 win32APICALL(PeekConsoleInput(hConsoleInput
, &ir
, 1, &dw
));
184 win32APICALL(ReadConsoleInput(hConsoleInput
, &ir
, 1, &dw
));
185 switch (ir
.EventType
) {
187 if (!ir
.Event
.KeyEvent
.bKeyDown
) /* Process key just once: when pressed */
190 vkcode
= ir
.Event
.KeyEvent
.wVirtualKeyCode
;
191 //#ifndef __MINGW32__
192 ch
= ir
.Event
.KeyEvent
.uChar
.AsciiChar
;
194 // ch = ir.Event.KeyEvent.AsciiChar;
196 dwSaved_ControlState
= ir
.Event
.KeyEvent
.dwControlKeyState
;
197 j
= translate_key_code (ch
, vkcode
);
203 /* Save event as a GPM-like event */
204 evSaved_Event
.x
= ir
.Event
.MouseEvent
.dwMousePosition
.X
;
205 evSaved_Event
.y
= ir
.Event
.MouseEvent
.dwMousePosition
.Y
+1;
206 evSaved_Event
.buttons
= ir
.Event
.MouseEvent
.dwButtonState
;
207 switch (ir
.Event
.MouseEvent
.dwEventFlags
) {
209 evSaved_Event
.type
= GPM_DOWN
| GPM_SINGLE
;
212 evSaved_Event
.type
= GPM_MOVE
;
215 evSaved_Event
.type
= GPM_DOWN
| GPM_DOUBLE
;
224 static int getch_with_delay (void)
229 /* Try to get a character */
230 c
= get_key_code (0);
234 /* Success -> return the character */
238 /* Returns a character read from stdin with appropriate interpretation */
239 int get_event (Gpm_Event
*event
, int redo_event
, int block
)
242 static int flag
; /* Return value from select */
243 static int dirty
= 3;
245 if ((dirty
== 1) || is_idle ()){
252 vfs_timeout_handler ();
254 c
= block
? getch_with_delay () : get_key_code (1);
257 /* Code is 0, so this is a Control key or mouse event */
258 return EV_NONE
; /* FIXME: mouse not supported */
264 /* Returns a key press, mouse events are discarded */
270 while ((key
= get_event (&ev
, 0, 1)) == 0)
276 is_idle - A function to check if we're idle.
277 It checks for any waiting event (that can be a Key, Mouse event,
278 and other internal events like focus or menu)
283 if (GetNumberOfConsoleInputEvents (hConsoleInput
, &dw
))
294 if (dwSaved_ControlState
& LEFT_ALT_PRESSED
) /* code is not clean, because we return Linux-like bitcodes*/
295 retval
|= ALTL_PRESSED
;
296 if (dwSaved_ControlState
& RIGHT_ALT_PRESSED
)
297 retval
|= ALTR_PRESSED
;
299 if (dwSaved_ControlState
& RIGHT_CTRL_PRESSED
||
300 dwSaved_ControlState
& LEFT_CTRL_PRESSED
)
301 retval
|= CONTROL_PRESSED
;
303 if (dwSaved_ControlState
& SHIFT_PRESSED
)
304 retval
|= SHIFT_PRESSED
;
309 /* void functions for UNIX compatibility */
310 int define_sequence (int code
, char* vkcode
, int action
) { return 1; }
311 void channels_up() {}
312 void channels_down() {}
313 void init_key_input_fd (void) {}
314 void numeric_keypad_mode (void) {}
315 void application_keypad_mode (void) {}
317 /* mouse is not yet supported, sorry */
318 void init_mouse (void) {}
319 void shut_mouse (void) {}
321 #endif /* NATIVE_WIN32 */