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., 675 Mass Ave, Cambridge, MA 02139, 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
},
89 { ALT('\t'), VK_PAUSE
}, /* Added to make Complete work press Pause */
91 { ESC_CHAR
, VK_ESCAPE
},
96 /* init_key - Called in main.c to initialize ourselves
97 Get handle to console input
101 win32APICALL_HANDLE (hConsoleInput
, GetStdHandle (STD_INPUT_HANDLE
));
106 if(dwSaved_ControlState
& RIGHT_ALT_PRESSED
) return 0;
107 /* The line above fixes the BUG with the AltGr Keys*/
108 return dwSaved_ControlState
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
);
113 if(dwSaved_ControlState
& RIGHT_ALT_PRESSED
) return 0;
114 /* The line above fixes the BUG with the AltGr Keys*/
115 return dwSaved_ControlState
& SHIFT_PRESSED
;
120 return dwSaved_ControlState
& (/* RIGHT_ALT_PRESSED | */ LEFT_ALT_PRESSED
);
123 static int VKtoCurses (int a_vkc
)
127 for (i
= 0; key_table
[i
].vkcode
!= 0; i
++)
128 if (a_vkc
== key_table
[i
].vkcode
) {
129 return key_table
[i
].key_code
;
134 static int translate_key_code(int asc
, int scan
)
138 case 106: /* KP_MULT*/
140 case 107: /* KP_PLUS*/
142 case 109: /* KP_MINUS*/
145 c
= VKtoCurses (scan
);
150 if (!asc
|| asc
=='\t' )
152 if (shift_pressed() && (c
>= KEY_F(1)) && (c
<= KEY_F(10)))
154 if (alt_pressed() && (c
>= KEY_F(1)) && (c
<= KEY_F(2)))
156 if (alt_pressed() && (c
== KEY_F(7)))
159 if(ctrl_pressed())c
= ALT('\t');
173 int get_key_code (int no_delay
)
175 INPUT_RECORD ir
; /* Input record */
176 DWORD dw
; /* number of records actually read */
180 /* Check if any input pending, otherwise return */
181 nodelay (stdscr
, TRUE
);
182 win32APICALL(PeekConsoleInput(hConsoleInput
, &ir
, 1, &dw
));
188 win32APICALL(ReadConsoleInput(hConsoleInput
, &ir
, 1, &dw
));
189 switch (ir
.EventType
) {
191 if (!ir
.Event
.KeyEvent
.bKeyDown
) /* Process key just once: when pressed */
194 vkcode
= ir
.Event
.KeyEvent
.wVirtualKeyCode
;
195 //#ifndef __MINGW32__
196 ch
= ir
.Event
.KeyEvent
.uChar
.AsciiChar
;
198 // ch = ir.Event.KeyEvent.AsciiChar;
200 dwSaved_ControlState
= ir
.Event
.KeyEvent
.dwControlKeyState
;
201 j
= translate_key_code (ch
, vkcode
);
207 /* Save event as a GPM-like event */
208 evSaved_Event
.x
= ir
.Event
.MouseEvent
.dwMousePosition
.X
;
209 evSaved_Event
.y
= ir
.Event
.MouseEvent
.dwMousePosition
.Y
+1;
210 evSaved_Event
.buttons
= ir
.Event
.MouseEvent
.dwButtonState
;
211 switch (ir
.Event
.MouseEvent
.dwEventFlags
) {
213 evSaved_Event
.type
= GPM_DOWN
| GPM_SINGLE
;
216 evSaved_Event
.type
= GPM_MOVE
;
219 evSaved_Event
.type
= GPM_DOWN
| GPM_DOUBLE
;
228 static int getch_with_delay (void)
233 /* Try to get a character */
234 c
= get_key_code (0);
238 /* Success -> return the character */
242 /* Returns a character read from stdin with appropriate interpretation */
243 int get_event (Gpm_Event
*event
, int redo_event
, int block
)
246 static int flag
; /* Return value from select */
247 static int dirty
= 3;
249 if ((dirty
== 1) || is_idle ()){
256 vfs_timeout_handler ();
258 c
= block
? getch_with_delay () : get_key_code (1);
261 /* Code is 0, so this is a Control key or mouse event */
262 return EV_NONE
; /* FIXME: mouse not supported */
268 /* Returns a key press, mouse events are discarded */
274 while ((key
= get_event (&ev
, 0, 1)) == 0)
280 is_idle - A function to check if we're idle.
281 It checks for any waiting event (that can be a Key, Mouse event,
282 and other internal events like focus or menu)
287 if (GetNumberOfConsoleInputEvents (hConsoleInput
, &dw
))
298 if (dwSaved_ControlState
& LEFT_ALT_PRESSED
) /* code is not clean, because we return Linux-like bitcodes*/
299 retval
|= ALTL_PRESSED
;
300 if (dwSaved_ControlState
& RIGHT_ALT_PRESSED
)
301 retval
|= ALTR_PRESSED
;
303 if (dwSaved_ControlState
& RIGHT_CTRL_PRESSED
||
304 dwSaved_ControlState
& LEFT_CTRL_PRESSED
)
305 retval
|= CONTROL_PRESSED
;
307 if (dwSaved_ControlState
& SHIFT_PRESSED
)
308 retval
|= SHIFT_PRESSED
;
313 /* void functions for UNIX compatibility */
314 void define_sequence (int code
, char* vkcode
, int action
) {}
315 void channels_up() {}
316 void channels_down() {}
317 void init_key_input_fd (void) {}
318 void numeric_keypad_mode (void) {}
319 void application_keypad_mode (void) {}
321 /* mouse is not yet supported, sorry */
322 void init_mouse (void) {}
323 void shut_mouse (void) {}