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.
28 #include "../src/mouse.h"
29 #include "../src/global.h"
30 #include "../src/main.h"
31 #include "../src/key.h"
32 #include "../vfs/vfs.h"
33 #include "../src/tty.h"
36 /* Global variables */
39 DWORD dwSaved_ControlState
;
40 Gpm_Event evSaved_Event
;
42 /* Unused variables */
43 int double_click_speed
; /* they are here to keep linker happy */
45 int use_8th_bit_as_meta
= 0;
61 { KEY_F(10), VK_F10
},
62 { KEY_F(11), VK_F11
},
63 { KEY_F(12), VK_F12
},
64 { KEY_F(13), VK_F13
},
65 { KEY_F(14), VK_F14
},
66 { KEY_F(15), VK_F15
},
67 { KEY_F(16), VK_F16
},
68 { KEY_F(17), VK_F17
},
69 { KEY_F(18), VK_F18
},
70 { KEY_F(19), VK_F19
},
71 { KEY_F(20), VK_F20
},
72 { KEY_IC
, VK_INSERT
},
73 { KEY_DC
, VK_DELETE
},
74 { KEY_BACKSPACE
, VK_BACK
},
76 { KEY_PPAGE
, VK_PRIOR
},
77 { KEY_NPAGE
, VK_NEXT
},
78 { KEY_LEFT
, VK_LEFT
},
79 { KEY_RIGHT
, VK_RIGHT
},
81 { KEY_DOWN
, VK_DOWN
},
82 { KEY_HOME
, VK_HOME
},
85 { ALT('*'), VK_MULTIPLY
},
87 { ALT('-'), VK_SUBTRACT
},
88 { ALT('\t'), VK_PAUSE
}, /* Added to make Complete work press Pause */
90 { ESC_CHAR
, VK_ESCAPE
},
95 /* init_key - Called in main.c to initialize ourselves
96 Get handle to console input
100 win32APICALL_HANDLE (hConsoleInput
, GetStdHandle (STD_INPUT_HANDLE
));
105 if(dwSaved_ControlState
& RIGHT_ALT_PRESSED
) return 0;
106 /* The line above fixes the BUG with the AltGr Keys*/
107 return dwSaved_ControlState
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
);
112 return dwSaved_ControlState
& SHIFT_PRESSED
;
117 return dwSaved_ControlState
& (/* RIGHT_ALT_PRESSED |*/ LEFT_ALT_PRESSED
);
120 static int VKtoCurses (int a_vkc
)
124 for (i
= 0; fkt_table
[i
].vkcode
!= 0; i
++)
125 if (a_vkc
== fkt_table
[i
].vkcode
) {
126 return fkt_table
[i
].key_code
;
131 static int translate_key_code(int asc
, int scan
)
135 case 106: /* KP_MULT*/
137 case 107: /* KP_PLUS*/
139 case 109: /* KP_MINUS*/
142 c
= VKtoCurses (scan
);
147 if (!asc
|| asc
=='\t' )
149 if (shift_pressed() && (c
>= KEY_F(1)) && (c
<= KEY_F(10)))
151 if (alt_pressed() && (c
>= KEY_F(1)) && (c
<= KEY_F(2)))
153 if (alt_pressed() && (c
== KEY_F(7)))
156 if(ctrl_pressed())c
= ALT('\t');
170 int get_key_code (int no_delay
)
172 INPUT_RECORD ir
; /* Input record */
173 DWORD dw
; /* number of records actually read */
177 /* Check if any input pending, otherwise return */
178 nodelay (stdscr
, TRUE
);
179 win32APICALL(PeekConsoleInput(hConsoleInput
, &ir
, 1, &dw
));
185 win32APICALL(ReadConsoleInput(hConsoleInput
, &ir
, 1, &dw
));
186 switch (ir
.EventType
) {
188 if (!ir
.Event
.KeyEvent
.bKeyDown
) /* Process key just once: when pressed */
191 vkcode
= ir
.Event
.KeyEvent
.wVirtualKeyCode
;
192 //#ifndef __MINGW32__
193 ch
= ir
.Event
.KeyEvent
.uChar
.AsciiChar
;
195 // ch = ir.Event.KeyEvent.AsciiChar;
197 dwSaved_ControlState
= ir
.Event
.KeyEvent
.dwControlKeyState
;
198 j
= translate_key_code (ch
, vkcode
);
204 /* Save event as a GPM-like event */
205 evSaved_Event
.x
= ir
.Event
.MouseEvent
.dwMousePosition
.X
;
206 evSaved_Event
.y
= ir
.Event
.MouseEvent
.dwMousePosition
.Y
+1;
207 evSaved_Event
.buttons
= ir
.Event
.MouseEvent
.dwButtonState
;
208 switch (ir
.Event
.MouseEvent
.dwEventFlags
) {
210 evSaved_Event
.type
= GPM_DOWN
| GPM_SINGLE
;
213 evSaved_Event
.type
= GPM_MOVE
;
216 evSaved_Event
.type
= GPM_DOWN
| GPM_DOUBLE
;
225 static int getch_with_delay (void)
230 /* Try to get a character */
231 c
= get_key_code (0);
235 /* Success -> return the character */
239 /* Returns a character read from stdin with appropriate interpretation */
240 int get_event (Gpm_Event
*event
, int redo_event
, int block
)
243 static int flag
; /* Return value from select */
244 static int dirty
= 3;
246 if ((dirty
== 1) || is_idle ()){
253 vfs_timeout_handler ();
255 c
= block
? getch_with_delay () : get_key_code (1);
258 /* Code is 0, so this is a Control key or mouse event */
259 return EV_NONE
; /* FIXME: mouse not supported */
265 /* Returns a key press, mouse events are discarded */
271 while ((key
= get_event (&ev
, 0, 1)) == 0)
277 is_idle - A function to check if we're idle.
278 It checks for any waiting event (that can be a Key, Mouse event,
279 and other internal events like focus or menu)
284 if (GetNumberOfConsoleInputEvents (hConsoleInput
, &dw
))
295 if (dwSaved_ControlState
& LEFT_ALT_PRESSED
) /* code is not clean, because we return Linux-like bitcodes*/
296 retval
|= ALTL_PRESSED
;
297 if (dwSaved_ControlState
& RIGHT_ALT_PRESSED
)
298 retval
|= ALTR_PRESSED
;
300 if (dwSaved_ControlState
& RIGHT_CTRL_PRESSED
||
301 dwSaved_ControlState
& LEFT_CTRL_PRESSED
)
302 retval
|= CONTROL_PRESSED
;
304 if (dwSaved_ControlState
& SHIFT_PRESSED
)
305 retval
|= SHIFT_PRESSED
;
310 /* void functions for UNIX compatibility */
311 void define_sequence (int code
, char* vkcode
, int action
) {}
312 void channels_up() {}
313 void channels_down() {}
314 void init_key_input_fd (void) {}
315 void numeric_keypad_mode (void) {}
316 void application_keypad_mode (void) {}
318 /* mouse is not yet supported, sorry */
319 void init_mouse (void) {}
320 void shut_mouse (void) {}