16884
|
1 /* Input event support for Emacs on the Microsoft W32 API.
|
11386
|
2 Copyright (C) 1992, 1993, 1995 Free Software Foundation, Inc.
|
9907
|
3
|
14186
|
4 This file is part of GNU Emacs.
|
9907
|
5
|
14186
|
6 GNU Emacs 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, or (at your option)
|
|
9 any later version.
|
9907
|
10
|
14186
|
11 GNU Emacs 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.
|
9907
|
15
|
14186
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with GNU Emacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA.
|
9907
|
20
|
|
21 Drew Bliss 01-Oct-93
|
|
22 Adapted from ntkbd.c by Tim Fleehart
|
|
23 */
|
|
24
|
|
25
|
42469
|
26 #ifdef HAVE_CONFIG_H
|
|
27 #include <config.h>
|
|
28 #endif
|
9907
|
29
|
|
30 #include <stdlib.h>
|
|
31 #include <stdio.h>
|
|
32 #include <windows.h>
|
|
33
|
31113
|
34 #ifndef MOUSE_MOVED
|
|
35 #define MOUSE_MOVED 1
|
|
36 #endif
|
|
37
|
9907
|
38 #include "lisp.h"
|
31113
|
39 #include "keyboard.h"
|
9907
|
40 #include "frame.h"
|
|
41 #include "blockinput.h"
|
|
42 #include "termhooks.h"
|
23679
|
43 #include "w32heap.h"
|
|
44 #include "w32term.h"
|
9907
|
45
|
|
46 /* stdin, from ntterm */
|
|
47 extern HANDLE keyboard_handle;
|
|
48
|
|
49 /* Info for last mouse motion */
|
|
50 static COORD movement_pos;
|
|
51 static DWORD movement_time;
|
|
52
|
|
53 /* from keyboard.c */
|
|
54 extern void reinvoke_input_signal (void);
|
|
55
|
|
56 /* from dispnew.c */
|
|
57 extern int change_frame_size (FRAME_PTR, int, int, int, int);
|
|
58
|
24937
42f29912dc46
(w32_console_read_socket): Use new variable w32_use_full_screen_buffer.
Andrew Innes <andrewi@gnu.org>
diff
changeset
|
59 /* from w32console.c */
|
42f29912dc46
(w32_console_read_socket): Use new variable w32_use_full_screen_buffer.
Andrew Innes <andrewi@gnu.org>
diff
changeset
|
60 extern int w32_use_full_screen_buffer;
|
42f29912dc46
(w32_console_read_socket): Use new variable w32_use_full_screen_buffer.
Andrew Innes <andrewi@gnu.org>
diff
changeset
|
61
|
15460
|
62 /* from w32fns.c */
|
16588
|
63 extern Lisp_Object Vw32_alt_is_meta;
|
23679
|
64 extern unsigned int map_keypad_keys (unsigned int, unsigned int);
|
15460
|
65
|
19710
|
66 /* from w32term */
|
|
67 extern Lisp_Object Vw32_capslock_is_shiftlock;
|
23679
|
68 extern Lisp_Object Vw32_enable_caps_lock;
|
|
69 extern Lisp_Object Vw32_enable_num_lock;
|
21611
|
70 extern Lisp_Object Vw32_recognize_altgr;
|
23679
|
71 extern Lisp_Object Vw32_pass_lwindow_to_system;
|
|
72 extern Lisp_Object Vw32_pass_rwindow_to_system;
|
23804
|
73 extern Lisp_Object Vw32_phantom_key_code;
|
23679
|
74 extern Lisp_Object Vw32_lwindow_modifier;
|
|
75 extern Lisp_Object Vw32_rwindow_modifier;
|
|
76 extern Lisp_Object Vw32_apps_modifier;
|
|
77 extern Lisp_Object Vw32_scroll_lock_modifier;
|
|
78 extern unsigned int w32_key_to_modifier (int key);
|
19710
|
79
|
9907
|
80 /* Event queue */
|
|
81 #define EVENT_QUEUE_SIZE 50
|
|
82 static INPUT_RECORD event_queue[EVENT_QUEUE_SIZE];
|
|
83 static INPUT_RECORD *queue_ptr = event_queue, *queue_end = event_queue;
|
|
84
|
49600
|
85 static int
|
9907
|
86 fill_queue (BOOL block)
|
|
87 {
|
|
88 BOOL rc;
|
|
89 DWORD events_waiting;
|
49600
|
90
|
9907
|
91 if (queue_ptr < queue_end)
|
|
92 return queue_end-queue_ptr;
|
49600
|
93
|
9907
|
94 if (!block)
|
|
95 {
|
|
96 /* Check to see if there are some events to read before we try
|
|
97 because we can't block. */
|
|
98 if (!GetNumberOfConsoleInputEvents (keyboard_handle, &events_waiting))
|
|
99 return -1;
|
|
100 if (events_waiting == 0)
|
|
101 return 0;
|
|
102 }
|
49600
|
103
|
9907
|
104 rc = ReadConsoleInput (keyboard_handle, event_queue, EVENT_QUEUE_SIZE,
|
|
105 &events_waiting);
|
|
106 if (!rc)
|
|
107 return -1;
|
|
108 queue_ptr = event_queue;
|
|
109 queue_end = event_queue + events_waiting;
|
|
110 return (int) events_waiting;
|
|
111 }
|
|
112
|
|
113 /* In a generic, multi-frame world this should take a console handle
|
|
114 and return the frame for it
|
|
115
|
|
116 Right now, there's only one frame so return it. */
|
49600
|
117 static FRAME_PTR
|
9907
|
118 get_frame (void)
|
|
119 {
|
27399
|
120 return SELECTED_FRAME ();
|
9907
|
121 }
|
|
122
|
49600
|
123 /* Translate console modifiers to emacs modifiers.
|
11386
|
124 German keyboard support (Kai Morgan Zeise 2/18/95). */
|
15144
|
125 int
|
19710
|
126 w32_kbd_mods_to_emacs (DWORD mods, WORD key)
|
11386
|
127 {
|
|
128 int retval = 0;
|
|
129
|
21611
|
130 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
|
23679
|
131 pressed, first remove those modifiers. */
|
49600
|
132 if (!NILP (Vw32_recognize_altgr)
|
|
133 && (mods & (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
|
11386
|
134 == (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
|
|
135 mods &= ~ (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED);
|
|
136
|
|
137 if (mods & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED))
|
16588
|
138 retval = ((NILP (Vw32_alt_is_meta)) ? alt_modifier : meta_modifier);
|
49600
|
139
|
11386
|
140 if (mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
|
|
141 {
|
|
142 retval |= ctrl_modifier;
|
49600
|
143 if ((mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
|
11386
|
144 == (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
|
|
145 retval |= meta_modifier;
|
|
146 }
|
|
147
|
23679
|
148 if (mods & LEFT_WIN_PRESSED)
|
|
149 retval |= w32_key_to_modifier (VK_LWIN);
|
|
150 if (mods & RIGHT_WIN_PRESSED)
|
|
151 retval |= w32_key_to_modifier (VK_RWIN);
|
|
152 if (mods & APPS_PRESSED)
|
|
153 retval |= w32_key_to_modifier (VK_APPS);
|
|
154 if (mods & SCROLLLOCK_ON)
|
|
155 retval |= w32_key_to_modifier (VK_SCROLL);
|
|
156
|
19710
|
157 /* Just in case someone wanted the original behaviour, make it
|
|
158 optional by setting w32-capslock-is-shiftlock to t. */
|
23679
|
159 if (NILP (Vw32_capslock_is_shiftlock)
|
|
160 /* Keys that should _not_ be affected by CapsLock. */
|
|
161 && ( (key == VK_BACK)
|
|
162 || (key == VK_TAB)
|
|
163 || (key == VK_CLEAR)
|
|
164 || (key == VK_RETURN)
|
|
165 || (key == VK_ESCAPE)
|
|
166 || ((key >= VK_SPACE) && (key <= VK_HELP))
|
|
167 || ((key >= VK_NUMPAD0) && (key <= VK_F24))
|
|
168 || ((key >= VK_NUMPAD_CLEAR) && (key <= VK_NUMPAD_DELETE))
|
|
169 ))
|
19710
|
170 {
|
23679
|
171 /* Only consider shift state. */
|
|
172 if ((mods & SHIFT_PRESSED) != 0)
|
19710
|
173 retval |= shift_modifier;
|
|
174 }
|
|
175 else
|
|
176 {
|
23679
|
177 /* Ignore CapsLock state if not enabled. */
|
|
178 if (NILP (Vw32_enable_caps_lock))
|
|
179 mods &= ~CAPSLOCK_ON;
|
|
180 if ((mods & (SHIFT_PRESSED | CAPSLOCK_ON)) != 0)
|
|
181 retval |= shift_modifier;
|
19710
|
182 }
|
11386
|
183
|
|
184 return retval;
|
|
185 }
|
|
186
|
23679
|
187 #if 0
|
|
188 /* Return nonzero if the virtual key is a dead key. */
|
|
189 static int
|
|
190 is_dead_key (int wparam)
|
|
191 {
|
|
192 unsigned int code = MapVirtualKey (wparam, 2);
|
|
193
|
|
194 /* Windows 95 returns 0x8000, NT returns 0x80000000. */
|
|
195 return (code & 0x80008000) ? 1 : 0;
|
|
196 }
|
|
197 #endif
|
|
198
|
14245
|
199 /* The return code indicates key code size. */
|
14463
|
200 int
|
16588
|
201 w32_kbd_patch_key (KEY_EVENT_RECORD *event)
|
9907
|
202 {
|
11386
|
203 unsigned int key_code = event->wVirtualKeyCode;
|
|
204 unsigned int mods = event->dwControlKeyState;
|
14245
|
205 BYTE keystate[256];
|
|
206 static BYTE ansi_code[4];
|
15144
|
207 static int isdead = 0;
|
11386
|
208
|
14245
|
209 if (isdead == 2)
|
|
210 {
|
|
211 event->uChar.AsciiChar = ansi_code[2];
|
|
212 isdead = 0;
|
|
213 return 1;
|
11386
|
214 }
|
49600
|
215 if (event->uChar.AsciiChar != 0)
|
14245
|
216 return 1;
|
14463
|
217
|
14245
|
218 memset (keystate, 0, sizeof (keystate));
|
23679
|
219 keystate[key_code] = 0x80;
|
49600
|
220 if (mods & SHIFT_PRESSED)
|
14245
|
221 keystate[VK_SHIFT] = 0x80;
|
49600
|
222 if (mods & CAPSLOCK_ON)
|
14245
|
223 keystate[VK_CAPITAL] = 1;
|
21611
|
224 /* If we recognize right-alt and left-ctrl as AltGr, set the key
|
|
225 states accordingly before invoking ToAscii. */
|
|
226 if (!NILP (Vw32_recognize_altgr)
|
|
227 && (mods & LEFT_CTRL_PRESSED) && (mods & RIGHT_ALT_PRESSED))
|
14463
|
228 {
|
|
229 keystate[VK_CONTROL] = 0x80;
|
|
230 keystate[VK_LCONTROL] = 0x80;
|
|
231 keystate[VK_MENU] = 0x80;
|
|
232 keystate[VK_RMENU] = 0x80;
|
|
233 }
|
|
234
|
23679
|
235 #if 0
|
|
236 /* Because of an OS bug, ToAscii corrupts the stack when called to
|
|
237 convert a dead key in console mode on NT4. Unfortunately, trying
|
|
238 to check for dead keys using MapVirtualKey doesn't work either -
|
|
239 these functions apparently use internal information about keyboard
|
|
240 layout which doesn't get properly updated in console programs when
|
|
241 changing layout (though apparently it gets partly updated,
|
|
242 otherwise ToAscii wouldn't crash). */
|
|
243 if (is_dead_key (event->wVirtualKeyCode))
|
|
244 return 0;
|
|
245 #endif
|
|
246
|
|
247 /* On NT, call ToUnicode instead and then convert to the current
|
|
248 locale's default codepage. */
|
|
249 if (os_subtype == OS_NT)
|
|
250 {
|
|
251 WCHAR buf[128];
|
|
252
|
|
253 isdead = ToUnicode (event->wVirtualKeyCode, event->wVirtualScanCode,
|
|
254 keystate, buf, 128, 0);
|
|
255 if (isdead > 0)
|
|
256 {
|
|
257 char cp[20];
|
|
258 int cpId;
|
|
259
|
|
260 GetLocaleInfo (GetThreadLocale (),
|
|
261 LOCALE_IDEFAULTANSICODEPAGE, cp, 20);
|
|
262 cpId = atoi (cp);
|
|
263 isdead = WideCharToMultiByte (cpId, 0, buf, isdead,
|
|
264 ansi_code, 4, NULL, NULL);
|
|
265 }
|
|
266 else
|
|
267 isdead = 0;
|
|
268 }
|
|
269 else
|
|
270 {
|
|
271 isdead = ToAscii (event->wVirtualKeyCode, event->wVirtualScanCode,
|
|
272 keystate, (LPWORD) ansi_code, 0);
|
|
273 }
|
|
274
|
49600
|
275 if (isdead == 0)
|
14245
|
276 return 0;
|
|
277 event->uChar.AsciiChar = ansi_code[0];
|
|
278 return isdead;
|
9907
|
279 }
|
15144
|
280
|
9907
|
281
|
23679
|
282 extern char *lispy_function_keys[];
|
9907
|
283
|
23804
|
284 static int faked_key = 0;
|
|
285
|
49600
|
286 /* return code -1 means that event_queue_ptr won't be incremented.
|
14245
|
287 In other word, this event makes two key codes. (by himi) */
|
49600
|
288 int
|
19710
|
289 key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead)
|
9907
|
290 {
|
23679
|
291 static int mod_key_state = 0;
|
|
292 int wParam;
|
19710
|
293
|
|
294 *isdead = 0;
|
23679
|
295
|
9907
|
296 /* Skip key-up events. */
|
15144
|
297 if (!event->bKeyDown)
|
9907
|
298 {
|
23679
|
299 switch (event->wVirtualKeyCode)
|
|
300 {
|
|
301 case VK_LWIN:
|
|
302 mod_key_state &= ~LEFT_WIN_PRESSED;
|
|
303 break;
|
|
304 case VK_RWIN:
|
|
305 mod_key_state &= ~RIGHT_WIN_PRESSED;
|
|
306 break;
|
|
307 case VK_APPS:
|
|
308 mod_key_state &= ~APPS_PRESSED;
|
|
309 break;
|
|
310 }
|
|
311 return 0;
|
|
312 }
|
|
313
|
|
314 /* Ignore keystrokes we fake ourself; see below. */
|
|
315 if (faked_key == event->wVirtualKeyCode)
|
|
316 {
|
|
317 faked_key = 0;
|
9907
|
318 return 0;
|
|
319 }
|
11386
|
320
|
23679
|
321 /* To make it easier to debug this code, ignore modifier keys! */
|
|
322 switch (event->wVirtualKeyCode)
|
11386
|
323 {
|
23679
|
324 case VK_LWIN:
|
|
325 if (NILP (Vw32_pass_lwindow_to_system))
|
|
326 {
|
|
327 /* Prevent system from acting on keyup (which opens the Start
|
|
328 menu if no other key was pressed) by simulating a press of
|
|
329 Space which we will ignore. */
|
|
330 if ((mod_key_state & LEFT_WIN_PRESSED) == 0)
|
|
331 {
|
23804
|
332 if (NUMBERP (Vw32_phantom_key_code))
|
|
333 faked_key = XUINT (Vw32_phantom_key_code) & 255;
|
|
334 else
|
|
335 faked_key = VK_SPACE;
|
|
336 keybd_event (faked_key, (BYTE) MapVirtualKey (faked_key, 0), 0, 0);
|
23679
|
337 }
|
|
338 }
|
|
339 mod_key_state |= LEFT_WIN_PRESSED;
|
|
340 if (!NILP (Vw32_lwindow_modifier))
|
|
341 return 0;
|
|
342 break;
|
|
343 case VK_RWIN:
|
|
344 if (NILP (Vw32_pass_rwindow_to_system))
|
|
345 {
|
|
346 if ((mod_key_state & RIGHT_WIN_PRESSED) == 0)
|
|
347 {
|
23804
|
348 if (NUMBERP (Vw32_phantom_key_code))
|
|
349 faked_key = XUINT (Vw32_phantom_key_code) & 255;
|
|
350 else
|
|
351 faked_key = VK_SPACE;
|
|
352 keybd_event (faked_key, (BYTE) MapVirtualKey (faked_key, 0), 0, 0);
|
23679
|
353 }
|
|
354 }
|
|
355 mod_key_state |= RIGHT_WIN_PRESSED;
|
|
356 if (!NILP (Vw32_rwindow_modifier))
|
|
357 return 0;
|
|
358 break;
|
|
359 case VK_APPS:
|
|
360 mod_key_state |= APPS_PRESSED;
|
|
361 if (!NILP (Vw32_apps_modifier))
|
|
362 return 0;
|
|
363 break;
|
|
364 case VK_CAPITAL:
|
|
365 /* Decide whether to treat as modifier or function key. */
|
|
366 if (NILP (Vw32_enable_caps_lock))
|
|
367 goto disable_lock_key;
|
|
368 return 0;
|
|
369 case VK_NUMLOCK:
|
|
370 /* Decide whether to treat as modifier or function key. */
|
|
371 if (NILP (Vw32_enable_num_lock))
|
|
372 goto disable_lock_key;
|
|
373 return 0;
|
|
374 case VK_SCROLL:
|
|
375 /* Decide whether to treat as modifier or function key. */
|
|
376 if (NILP (Vw32_scroll_lock_modifier))
|
|
377 goto disable_lock_key;
|
|
378 return 0;
|
|
379 disable_lock_key:
|
|
380 /* Ensure the appropriate lock key state is off (and the
|
|
381 indicator light as well). */
|
|
382 wParam = event->wVirtualKeyCode;
|
|
383 if (GetAsyncKeyState (wParam) & 0x8000)
|
|
384 {
|
|
385 /* Fake another press of the relevant key. Apparently, this
|
|
386 really is the only way to turn off the indicator. */
|
|
387 faked_key = wParam;
|
|
388 keybd_event ((BYTE) wParam, (BYTE) MapVirtualKey (wParam, 0),
|
|
389 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
|
|
390 keybd_event ((BYTE) wParam, (BYTE) MapVirtualKey (wParam, 0),
|
|
391 KEYEVENTF_EXTENDEDKEY | 0, 0);
|
|
392 keybd_event ((BYTE) wParam, (BYTE) MapVirtualKey (wParam, 0),
|
|
393 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
|
|
394 }
|
|
395 break;
|
|
396 case VK_MENU:
|
|
397 case VK_CONTROL:
|
|
398 case VK_SHIFT:
|
9907
|
399 return 0;
|
23804
|
400 case VK_CANCEL:
|
|
401 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
|
|
402 which is confusing for purposes of key binding; convert
|
|
403 VK_CANCEL events into VK_PAUSE events. */
|
|
404 event->wVirtualKeyCode = VK_PAUSE;
|
|
405 break;
|
|
406 case VK_PAUSE:
|
|
407 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
|
|
408 for purposes of key binding; convert these back into
|
|
409 VK_NUMLOCK events, at least when we want to see NumLock key
|
|
410 presses. (Note that there is never any possibility that
|
|
411 VK_PAUSE with Ctrl really is C-Pause as per above.) */
|
|
412 if (NILP (Vw32_enable_num_lock)
|
|
413 && (event->dwControlKeyState
|
|
414 & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) != 0)
|
|
415 event->wVirtualKeyCode = VK_NUMLOCK;
|
|
416 break;
|
9907
|
417 }
|
23679
|
418
|
|
419 /* Recognize state of Windows and Apps keys. */
|
|
420 event->dwControlKeyState |= mod_key_state;
|
|
421
|
|
422 /* Distinguish numeric keypad keys from extended keys. */
|
|
423 event->wVirtualKeyCode =
|
|
424 map_keypad_keys (event->wVirtualKeyCode,
|
|
425 (event->dwControlKeyState & ENHANCED_KEY));
|
|
426
|
|
427 if (lispy_function_keys[event->wVirtualKeyCode] == 0)
|
9907
|
428 {
|
45804
|
429 emacs_ev->kind = ASCII_KEYSTROKE_EVENT;
|
23679
|
430
|
|
431 if (!NILP (Vw32_recognize_altgr)
|
|
432 && (event->dwControlKeyState & LEFT_CTRL_PRESSED)
|
|
433 && (event->dwControlKeyState & RIGHT_ALT_PRESSED))
|
|
434 {
|
|
435 /* Don't try to interpret AltGr key chords; ToAscii seems not
|
|
436 to process them correctly. */
|
|
437 }
|
|
438 /* Handle key chords including any modifiers other than shift
|
|
439 directly, in order to preserve as much modifier information as
|
|
440 possible. */
|
|
441 else if (event->dwControlKeyState
|
|
442 & ( RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED
|
|
443 | RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED
|
|
444 | (!NILP (Vw32_lwindow_modifier) ? LEFT_WIN_PRESSED : 0)
|
|
445 | (!NILP (Vw32_rwindow_modifier) ? RIGHT_WIN_PRESSED : 0)
|
|
446 | (!NILP (Vw32_apps_modifier) ? APPS_PRESSED : 0)
|
|
447 | (!NILP (Vw32_scroll_lock_modifier) ? SCROLLLOCK_ON : 0)))
|
|
448 {
|
|
449 /* Don't translate modified alphabetic keystrokes, so the user
|
|
450 doesn't need to constantly switch layout to type control or
|
|
451 meta keystrokes when the normal layout translates
|
|
452 alphabetic characters to non-ascii characters. */
|
|
453 if ('A' <= event->wVirtualKeyCode && event->wVirtualKeyCode <= 'Z')
|
|
454 {
|
|
455 event->uChar.AsciiChar = event->wVirtualKeyCode;
|
|
456 if ((event->dwControlKeyState & SHIFT_PRESSED) == 0)
|
|
457 event->uChar.AsciiChar += ('a' - 'A');
|
|
458 }
|
|
459 /* Try to handle unrecognized keystrokes by determining the
|
|
460 base character (ie. translating the base key plus shift
|
|
461 modifier). */
|
|
462 else if (event->uChar.AsciiChar == 0)
|
|
463 w32_kbd_patch_key (event);
|
|
464 }
|
|
465 if (event->uChar.AsciiChar == 0)
|
14245
|
466 return 0;
|
55640
|
467 emacs_ev->code = event->uChar.AsciiChar;
|
9907
|
468 }
|
|
469 else
|
|
470 {
|
45804
|
471 emacs_ev->kind = NON_ASCII_KEYSTROKE_EVENT;
|
55640
|
472 emacs_ev->code = event->wVirtualKeyCode;
|
9907
|
473 }
|
23679
|
474
|
11386
|
475 XSETFRAME (emacs_ev->frame_or_window, get_frame ());
|
19710
|
476 emacs_ev->modifiers = w32_kbd_mods_to_emacs (event->dwControlKeyState,
|
|
477 event->wVirtualKeyCode);
|
9907
|
478 emacs_ev->timestamp = GetTickCount ();
|
|
479 return 1;
|
|
480 }
|
|
481
|
23804
|
482 int
|
|
483 w32_console_toggle_lock_key (int vk_code, Lisp_Object new_state)
|
|
484 {
|
|
485 int cur_state = (GetKeyState (vk_code) & 1);
|
|
486
|
|
487 if (NILP (new_state)
|
|
488 || (NUMBERP (new_state)
|
35284
|
489 && ((XUINT (new_state)) & 1) != cur_state))
|
23804
|
490 {
|
|
491 faked_key = vk_code;
|
|
492
|
|
493 keybd_event ((BYTE) vk_code,
|
|
494 (BYTE) MapVirtualKey (vk_code, 0),
|
|
495 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
|
|
496 keybd_event ((BYTE) vk_code,
|
|
497 (BYTE) MapVirtualKey (vk_code, 0),
|
|
498 KEYEVENTF_EXTENDEDKEY | 0, 0);
|
|
499 keybd_event ((BYTE) vk_code,
|
|
500 (BYTE) MapVirtualKey (vk_code, 0),
|
|
501 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
|
|
502 cur_state = !cur_state;
|
|
503 }
|
|
504
|
|
505 return cur_state;
|
|
506 }
|
|
507
|
9907
|
508 /* Mouse position hook. */
|
49600
|
509 void
|
21829
|
510 w32_console_mouse_position (FRAME_PTR *f,
|
|
511 int insist,
|
|
512 Lisp_Object *bar_window,
|
|
513 enum scroll_bar_part *part,
|
|
514 Lisp_Object *x,
|
|
515 Lisp_Object *y,
|
|
516 unsigned long *time)
|
9907
|
517 {
|
|
518 BLOCK_INPUT;
|
15144
|
519
|
11386
|
520 insist = insist;
|
|
521
|
9907
|
522 *f = get_frame ();
|
|
523 *bar_window = Qnil;
|
|
524 *part = 0;
|
27399
|
525 SELECTED_FRAME ()->mouse_moved = 0;
|
49600
|
526
|
55640
|
527 XSETINT(*x, movement_pos.X);
|
|
528 XSETINT(*y, movement_pos.Y);
|
9907
|
529 *time = movement_time;
|
49600
|
530
|
9907
|
531 UNBLOCK_INPUT;
|
|
532 }
|
|
533
|
|
534 /* Remember mouse motion and notify emacs. */
|
49600
|
535 static void
|
9907
|
536 mouse_moved_to (int x, int y)
|
|
537 {
|
|
538 /* If we're in the same place, ignore it */
|
|
539 if (x != movement_pos.X || y != movement_pos.Y)
|
|
540 {
|
27399
|
541 SELECTED_FRAME ()->mouse_moved = 1;
|
9907
|
542 movement_pos.X = x;
|
|
543 movement_pos.Y = y;
|
|
544 movement_time = GetTickCount ();
|
|
545 }
|
|
546 }
|
|
547
|
|
548 /* Consoles return button bits in a strange order:
|
|
549 least significant - Leftmost button
|
|
550 next - Rightmost button
|
|
551 next - Leftmost+1
|
|
552 next - Leftmost+2...
|
|
553
|
|
554 Assume emacs likes three button mice, so
|
|
555 Left == 0
|
|
556 Middle == 1
|
|
557 Right == 2
|
|
558 Others increase from there. */
|
|
559
|
29319
|
560 #define NUM_TRANSLATED_MOUSE_BUTTONS 3
|
|
561 static int emacs_button_translation[NUM_TRANSLATED_MOUSE_BUTTONS] =
|
9907
|
562 {
|
29319
|
563 0, 2, 1
|
9907
|
564 };
|
|
565
|
49600
|
566 static int
|
9907
|
567 do_mouse_event (MOUSE_EVENT_RECORD *event,
|
|
568 struct input_event *emacs_ev)
|
|
569 {
|
|
570 static DWORD button_state = 0;
|
|
571 DWORD but_change, mask;
|
|
572 int i;
|
49600
|
573
|
9907
|
574 if (event->dwEventFlags == MOUSE_MOVED)
|
|
575 {
|
|
576 /* For movement events we just note that the mouse has moved
|
|
577 so that emacs will generate drag events. */
|
|
578 mouse_moved_to (event->dwMousePosition.X, event->dwMousePosition.Y);
|
|
579 return 0;
|
|
580 }
|
49600
|
581
|
9907
|
582 /* It looks like the console code sends us a mouse event with
|
|
583 dwButtonState == 0 when a window is activated. Ignore this case. */
|
|
584 if (event->dwButtonState == button_state)
|
|
585 return 0;
|
49600
|
586
|
45804
|
587 emacs_ev->kind = MOUSE_CLICK_EVENT;
|
49600
|
588
|
9907
|
589 /* Find out what button has changed state since the last button event. */
|
|
590 but_change = button_state ^ event->dwButtonState;
|
|
591 mask = 1;
|
29319
|
592 for (i = 0; mask; i++, mask <<= 1)
|
9907
|
593 if (but_change & mask)
|
|
594 {
|
29319
|
595 if (i < NUM_TRANSLATED_MOUSE_BUTTONS)
|
55640
|
596 emacs_ev->code = emacs_button_translation[i];
|
29319
|
597 else
|
55640
|
598 emacs_ev->code = i;
|
9907
|
599 break;
|
|
600 }
|
|
601
|
|
602 button_state = event->dwButtonState;
|
|
603 emacs_ev->timestamp = GetTickCount ();
|
19710
|
604 emacs_ev->modifiers = w32_kbd_mods_to_emacs (event->dwControlKeyState, 0) |
|
9907
|
605 ((event->dwButtonState & mask) ? down_modifier : up_modifier);
|
49600
|
606
|
10007
|
607 XSETFASTINT (emacs_ev->x, event->dwMousePosition.X);
|
|
608 XSETFASTINT (emacs_ev->y, event->dwMousePosition.Y);
|
14245
|
609 /* for Mule 2.2 (Based on Emacs 19.28 */
|
|
610 #ifdef MULE
|
|
611 XSET (emacs_ev->frame_or_window, Lisp_Frame, get_frame ());
|
|
612 #else
|
11386
|
613 XSETFRAME (emacs_ev->frame_or_window, get_frame ());
|
14245
|
614 #endif
|
49600
|
615
|
9907
|
616 return 1;
|
|
617 }
|
|
618
|
49600
|
619 static void
|
9907
|
620 resize_event (WINDOW_BUFFER_SIZE_RECORD *event)
|
|
621 {
|
|
622 FRAME_PTR f = get_frame ();
|
49600
|
623
|
9907
|
624 change_frame_size (f, event->dwSize.Y, event->dwSize.X, 0, 1);
|
|
625 SET_FRAME_GARBAGED (f);
|
|
626 }
|
|
627
|
24756
|
628 static void
|
|
629 maybe_generate_resize_event ()
|
|
630 {
|
|
631 CONSOLE_SCREEN_BUFFER_INFO info;
|
|
632 FRAME_PTR f = get_frame ();
|
|
633
|
|
634 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &info);
|
|
635
|
|
636 /* It is okay to call this unconditionally, since it will do nothing
|
|
637 if the size hasn't actually changed. */
|
|
638 change_frame_size (f,
|
|
639 1 + info.srWindow.Bottom - info.srWindow.Top,
|
|
640 1 + info.srWindow.Right - info.srWindow.Left,
|
|
641 0, 0);
|
|
642 }
|
|
643
|
49600
|
644 int
|
54169
|
645 w32_console_read_socket (int sd, int expected, struct input_event *hold_quit)
|
9907
|
646 {
|
|
647 BOOL no_events = TRUE;
|
|
648 int nev, ret = 0, add;
|
19710
|
649 int isdead;
|
|
650
|
9907
|
651 if (interrupt_input_blocked)
|
|
652 {
|
|
653 interrupt_input_pending = 1;
|
|
654 return -1;
|
|
655 }
|
49600
|
656
|
9907
|
657 interrupt_input_pending = 0;
|
|
658 BLOCK_INPUT;
|
49600
|
659
|
9907
|
660 for (;;)
|
|
661 {
|
15784
|
662 nev = fill_queue (0);
|
9907
|
663 if (nev <= 0)
|
|
664 {
|
|
665 /* If nev == -1, there was some kind of error
|
|
666 If nev == 0 then waitp must be zero and no events were available
|
|
667 so return. */
|
|
668 UNBLOCK_INPUT;
|
|
669 return nev;
|
|
670 }
|
|
671
|
54169
|
672 while (nev > 0)
|
9907
|
673 {
|
54169
|
674 struct input_event inev;
|
|
675
|
|
676 EVENT_INIT (inev);
|
|
677 inev.kind = NO_EVENT;
|
|
678 inev.arg = Qnil;
|
|
679
|
9907
|
680 switch (queue_ptr->EventType)
|
|
681 {
|
|
682 case KEY_EVENT:
|
54169
|
683 add = key_event (&queue_ptr->Event.KeyEvent, &inev, &isdead);
|
14245
|
684 if (add == -1) /* 95.7.25 by himi */
|
49600
|
685 {
|
14245
|
686 queue_ptr--;
|
|
687 add = 1;
|
|
688 }
|
54169
|
689 if (add)
|
|
690 kbd_buffer_store_event_hold (&inev, hold_quit);
|
9907
|
691 break;
|
|
692
|
|
693 case MOUSE_EVENT:
|
54169
|
694 add = do_mouse_event (&queue_ptr->Event.MouseEvent, &inev);
|
|
695 if (add)
|
|
696 kbd_buffer_store_event_hold (&inev, hold_quit);
|
9907
|
697 break;
|
|
698
|
|
699 case WINDOW_BUFFER_SIZE_EVENT:
|
24937
42f29912dc46
(w32_console_read_socket): Use new variable w32_use_full_screen_buffer.
Andrew Innes <andrewi@gnu.org>
diff
changeset
|
700 if (w32_use_full_screen_buffer)
|
42f29912dc46
(w32_console_read_socket): Use new variable w32_use_full_screen_buffer.
Andrew Innes <andrewi@gnu.org>
diff
changeset
|
701 resize_event (&queue_ptr->Event.WindowBufferSizeEvent);
|
9907
|
702 break;
|
49600
|
703
|
9907
|
704 case MENU_EVENT:
|
|
705 case FOCUS_EVENT:
|
|
706 /* Internal event types, ignored. */
|
|
707 break;
|
|
708 }
|
49600
|
709
|
9907
|
710 queue_ptr++;
|
|
711 nev--;
|
|
712 }
|
|
713
|
|
714 if (ret > 0 || expected == 0)
|
|
715 break;
|
|
716 }
|
24756
|
717
|
|
718 /* We don't get told about changes in the window size (only the buffer
|
|
719 size, which we no longer care about), so we have to check it
|
|
720 periodically. */
|
24937
42f29912dc46
(w32_console_read_socket): Use new variable w32_use_full_screen_buffer.
Andrew Innes <andrewi@gnu.org>
diff
changeset
|
721 if (!w32_use_full_screen_buffer)
|
42f29912dc46
(w32_console_read_socket): Use new variable w32_use_full_screen_buffer.
Andrew Innes <andrewi@gnu.org>
diff
changeset
|
722 maybe_generate_resize_event ();
|
24756
|
723
|
9907
|
724 UNBLOCK_INPUT;
|
|
725 return ret;
|
|
726 }
|
52401
|
727
|
|
728 /* arch-tag: 0bcb39b7-d085-4b85-9070-6750e8c03047
|
|
729 (do not change this comment) */
|