4 * Copyright 1993 Bob Amstadt
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1997 David Faure
7 * Copyright 1998 Morten Welinder
8 * Copyright 1998 Ulrich Weigand
9 * Copyright 1999 Ove Kåven
15 #ifndef X_DISPLAY_MISSING
17 #include <X11/Xatom.h>
18 #include <X11/keysym.h>
20 #include "ts_xresource.h"
23 #include "wine/winuser16.h"
31 DECLARE_DEBUG_CHANNEL(key
)
32 DECLARE_DEBUG_CHANNEL(keyboard
)
34 extern LPBYTE pKeyStateTable
;
36 int min_keycode
, max_keycode
, keysyms_per_keycode
;
37 WORD keyc2vkey
[256], keyc2scan
[256];
39 static int NumLockMask
, AltGrMask
; /* mask in the XKeyEvent state */
40 static int kcControl
, kcAlt
, kcShift
, kcNumLock
, kcCapsLock
; /* keycodes */
42 static char KEYBOARD_MapDeadKeysym(KeySym keysym
);
44 /* Keyboard translation tables */
46 static const int main_key_scan
[MAIN_LEN
] =
48 /* this is my (102-key) keyboard layout, sorry if it doesn't quite match yours */
49 0x29,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,
50 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,
51 0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x2B,
52 0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
53 0x56 /* the 102nd key (actually to the right of l-shift) */
56 /*** DEFINE YOUR NEW LANGUAGE-SPECIFIC MAPPINGS BELOW, SEE EXISTING TABLES */
58 /* the VK mappings for the main keyboard will be auto-assigned as before,
59 so what we have here is just the character tables */
60 /* order: Normal, Shift, AltGr, Shift-AltGr */
61 /* We recommend you write just what is guaranteed to be correct (i.e. what's
62 written on the keycaps), not the bunch of special characters behind AltGr
63 and Shift-AltGr if it can vary among different X servers */
64 /* Remember that your 102nd key (to the right of l-shift) should be on a
65 separate line, see existing tables */
66 /* If Wine fails to match your new table, use -debugmsg +key to find out why */
67 /* Remember to also add your new table to the layout index table far below! */
69 /*** United States keyboard layout (mostly contributed by Uwe Bonnes) */
70 static const char main_key_US
[MAIN_LEN
][4] =
72 "`~","1!","2@","3#","4$","5%","6^","7&","8*","9(","0)","-_","=+",
73 "qQ","wW","eE","rR","tT","yY","uU","iI","oO","pP","[{","]}",
74 "aA","sS","dD","fF","gG","hH","jJ","kK","lL",";:","'\"","\\|",
75 "zZ","xX","cC","vV","bB","nN","mM",",<",".>","/?"
78 /*** British keyboard layout */
79 static const char main_key_UK
[MAIN_LEN
][4] =
81 "`","1!","2\"","3£","4$","5%","6^","7&","8*","9(","0)","-_","=+",
82 "qQ","wW","eE","rR","tT","yY","uU","iI","oO","pP","[{","]}",
83 "aA","sS","dD","fF","gG","hH","jJ","kK","lL",";:","'@","#~",
84 "zZ","xX","cC","vV","bB","nN","mM",",<",".>","/?",
88 /*** French keyboard layout (contributed by Eric Pouech) */
89 static const char main_key_FR
[MAIN_LEN
][4] =
91 "²","&1","é2~","\"3#","'4{","(5[","-6|","è7","_8\\","ç9^±","à0@",")°]","=+}",
92 "aA","zZ","eE","rR","tT","yY","uU","iI","oO","pP","^¨","$£¤",
93 "qQ","sSß","dD","fF","gG","hH","jJ","kK","lL","mM","ù%","*µ",
94 "wW","xX","cC","vV","bB","nN",",?",";.",":/","!§",
98 /*** German keyboard layout (contributed by Ulrich Weigand) */
99 static const char main_key_DE
[MAIN_LEN
][4] =
101 "^°","1!","2\"","3§","4$","5%","6&","7/{","8([","9)]","0=}","ß?\\","'",
102 "qQ","wW","eE","rR","tT","zZ","uU","iI","oO","pP","üÜ","+*~",
103 "aA","sS","dD","fF","gG","hH","jJ","kK","lL","öÖ","äÄ","#´",
104 "yY","xX","cC","vV","bB","nN","mM",",;",".:","-_",
108 /*** Swiss German keyboard layout (contributed by Jonathan Naylor) */
109 static const char main_key_SG
[MAIN_LEN
][4] =
111 "§°","1+|","2\"@","3*#","4ç","5%","6&¬","7/¦","8(¢","9)","0=","'?´","^`~",
112 "qQ","wW","eE","rR","tT","zZ","uU","iI","oO","pP","üè[","¨!]",
113 "aA","sS","dD","fF","gG","hH","jJ","kK","lL","öé","äà{","$£}",
114 "yY","xX","cC","vV","bB","nN","mM",",;",".:","-_",
118 /*** Norwegian keyboard layout (contributed by Ove Kåven) */
119 static const char main_key_NO
[MAIN_LEN
][4] =
121 "|§","1!","2\"@","3#£","4¤$","5%","6&","7/{","8([","9)]","0=}","+?","\\`´",
122 "qQ","wW","eE","rR","tT","yY","uU","iI","oO","pP","åÅ","¨^~",
123 "aA","sS","dD","fF","gG","hH","jJ","kK","lL","øØ","æÆ","'*",
124 "zZ","xX","cC","vV","bB","nN","mM",",;",".:","-_",
128 /*** Danish keyboard layout (contributed by Bertho Stultiens) */
129 static const char main_key_DA
[MAIN_LEN
][4] =
131 "½§","1!","2\"@","3#£","4¤$","5%","6&","7/{","8([","9)]","0=}","+?","´`|",
132 "qQ","wW","eE","rR","tT","yY","uU","iI","oO","pP","åÅ","¨^~",
133 "aA","sS","dD","fF","gG","hH","jJ","kK","lL","æÆ","øØ","'*",
134 "zZ","xX","cC","vV","bB","nN","mM",",;",".:","-_",
138 /*** Canadian French keyboard layout */
139 static const char main_key_CF
[MAIN_LEN
][4] =
141 "#|\\","1!±","2\"@","3/£","4$¢","5%¤","6?¬","7&¦","8*²","9(³","0)³","-_½","=+¾",
142 "qQ","wW","eE","rR","tT","yY","uU","iI","oO§","pP¶","^^[","¨]",
143 "aA","sS","dD","fF","gG","hH","jJ","kK","lL",";:~","``{","<>}",
144 "zZ","xX","cC","vV","bB","nN","mM",",'_",".","éÉ",
148 /*** Portuguese keyboard layout */
149 static const char main_key_PT
[MAIN_LEN
][4] =
151 "\\¦","1!","2\"@","3#£","4$§","5%","6&","7/{","8([","9)]","0=}","'?","«»",
152 "qQ", "wW","eE", "rR", "tT", "yY", "uU", "iI", "oO", "pP", "+*\\¨","\\'\\`",
153 "aA", "sS","dD", "fF", "gG", "hH", "jJ", "kK", "lL", "çÇ", "ºª", "\\~\\^",
154 "zZ", "xX","cC", "vV", "bB", "nN", "mM", ",;", ".:", "-_",
158 /*** Finnish keyboard layout */
159 static const char main_key_FI
[MAIN_LEN
][4] =
161 "","1!","2\"@","3#","4$","5%","6&","7/{","8([","9)]","0=}","+?\\","\'`",
162 "qQ","wW","eE","rR","tT","yY","uU","iI","oO","pP","","\"^~",
163 "aA","sS","dD","fF","gG","hH","jJ","kK","lL","","","'*",
164 "zZ","xX","cC","vV","bB","nN","mM",",;",".:","-_",
168 /*** Russian keyboard layout (contributed by Pavel Roskin) */
169 static const char main_key_RU
[MAIN_LEN
][4] =
171 "`~","1!","2@","3#","4$","5%","6^","7&","8*","9(","0)","-_","=+",
172 "qQÊê","wWÃã","eEÕõ","rRËë","tTÅå","yYÎî","uUÇç","iIÛû","oOÝý","pPÚú","[{Èè","]}ßÿ",
173 "aAÆæ","sSÙù","dD×÷","fFÁá","gGÐð","hHÒò","jJÏï","kKÌì","lLÄä",";:Öö","'\"Üü","\\|",
174 "zZÑñ","xXÞþ","cCÓó","vVÍí","bBÉé","nNÔô","mMØø",",<Ââ",".>Àà","/?"
177 /*** Spanish keyboard layout (contributed by José Marcos López) */
178 static const char main_key_ES
[MAIN_LEN
][4] =
180 "ºª\\","1!|","2\"@","3·#","4$","5%","6&¬","7/","8(","9)","0=","'?","¡¿",
181 "qQ","wW","eE","rR","tT","yY","uU","iI","oO","pP","`^[","+*]",
182 "aA","sS","dD","fF","gG","hH","jJ","kK","lL","ñÑ","'¨{","çÇ}",
183 "zZ","xX","cC","vV","bB","nN","mM",",;",".:","-_",
187 /*** Belgian keyboard layout ***/
188 static const char main_key_BE
[MAIN_LEN
][4] =
190 "","&1|","é2@","\"3#","'4","(5","§6^","è7","!8","ç9{","à0}",")°","-_",
191 "aA","zZ","eE¤","rR","tT","yY","uU","iI","oO","pP","^¨[","$*]",
192 "qQ","sSß","dD","fF","gG","hH","jJ","kK","lL","mM","ù%´","µ£`",
193 "wW","xX","cC","vV","bB","nN",",?",";.",":/","=+~",
197 /*** Layout table. Add your keyboard mappings to this list */
199 WORD lang
, ansi_codepage
, oem_codepage
;
200 const char (*key
)[MAIN_LEN
][4];
202 {MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
), 1252, 437, &main_key_US
},
203 {MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_UK
), 1252, 850, &main_key_UK
},
204 {MAKELANGID(LANG_GERMAN
,SUBLANG_DEFAULT
), 1252, 850, &main_key_DE
},
205 {MAKELANGID(LANG_GERMAN
,SUBLANG_GERMAN_SWISS
), 1252, 850, &main_key_SG
},
206 {MAKELANGID(LANG_NORWEGIAN
,SUBLANG_DEFAULT
), 1252, 865, &main_key_NO
},
207 {MAKELANGID(LANG_DANISH
,SUBLANG_DEFAULT
), 1252, 865, &main_key_DA
},
208 {MAKELANGID(LANG_FRENCH
,SUBLANG_DEFAULT
), 1252, 850, &main_key_FR
},
209 {MAKELANGID(LANG_FRENCH
,SUBLANG_FRENCH_CANADIAN
), 1252, 863, &main_key_CF
},
210 {MAKELANGID(LANG_FRENCH
,SUBLANG_FRENCH_BELGIAN
), 1252, 850, &main_key_BE
},
211 {MAKELANGID(LANG_WALON
,SUBLANG_DEFAULT
), 1252, 850, &main_key_BE
},
212 {MAKELANGID(LANG_PORTUGUESE
,SUBLANG_DEFAULT
), 1252, 860, &main_key_PT
},
213 {MAKELANGID(LANG_FINNISH
,SUBLANG_DEFAULT
), 1252, 850, &main_key_FI
},
214 {MAKELANGID(LANG_RUSSIAN
,SUBLANG_DEFAULT
), 1251, 866, &main_key_RU
},
215 {MAKELANGID(LANG_SPANISH
,SUBLANG_DEFAULT
), 1252, 850, &main_key_ES
},
216 {MAKELANGID(LANG_DUTCH
,SUBLANG_DUTCH_BELGIAN
), 1252, 850, &main_key_BE
},
220 static unsigned kbd_layout
=0; /* index into above table of layouts */
222 /* maybe more of these scancodes should be extended? */
223 /* extended must be set for ALT_R, CTRL_R,
224 INS, DEL, HOME, END, PAGE_UP, PAGE_DOWN, ARROW keys,
225 keypad / and keypad ENTER (SDK 3.1 Vol.3 p 138) */
226 /* FIXME should we set extended bit for NumLock ? My
227 * Windows does ... DF */
228 static const int special_key_vkey
[] =
230 VK_BACK
, VK_TAB
, 0, VK_CLEAR
, 0, VK_RETURN
, 0, 0, /* FF08 */
231 0, 0, 0, VK_PAUSE
, VK_SCROLL
, 0, 0, 0, /* FF10 */
232 0, 0, 0, VK_ESCAPE
/* FF18 */
234 static const int special_key_scan
[] =
236 0x0E, 0x0F, 0, /*?*/ 0, 0, 0x1C, 0, 0, /* FF08 */
237 0, 0, 0, 0x45, 0x46, 0 , 0, 0, /* FF10 */
238 0, 0, 0, 0x01 /* FF18 */
241 static const int cursor_key_vkey
[] =
243 VK_HOME
, VK_LEFT
, VK_UP
, VK_RIGHT
, VK_DOWN
, VK_PRIOR
,
244 VK_NEXT
, VK_END
/* FF50 */
246 static const int cursor_key_scan
[] =
248 0x147, 0x14B, 0x148, 0x14D, 0x150, 0x149, 0x151, 0x14F /* FF50 */
251 static const int misc_key_vkey
[] =
253 VK_SELECT
, VK_SNAPSHOT
, VK_EXECUTE
, VK_INSERT
, 0, 0, 0, 0, /* FF60 */
254 VK_CANCEL
, VK_HELP
, VK_CANCEL
, VK_MENU
/* FF68 */
256 static const int misc_key_scan
[] =
258 /*?*/ 0, 0x37, /*?*/ 0, 0x152, 0, 0, 0, 0, /* FF60 */
259 /*?*/ 0, /*?*/ 0, 0x38 /* FF68 */
262 static const int keypad_key_vkey
[] =
264 0, VK_NUMLOCK
, /* FF7E */
265 0, 0, 0, 0, 0, 0, 0, 0, /* FF80 */
266 0, 0, 0, 0, 0, VK_RETURN
, 0, 0, /* FF88 */
267 0, 0, 0, 0, 0, VK_HOME
, VK_LEFT
, VK_UP
, /* FF90 */
268 VK_RIGHT
, VK_DOWN
, VK_PRIOR
, VK_NEXT
, VK_END
, 0,
269 VK_INSERT
, VK_DELETE
, /* FF98 */
270 0, 0, 0, 0, 0, 0, 0, 0, /* FFA0 */
271 0, 0, VK_MULTIPLY
, VK_ADD
, VK_SEPARATOR
, VK_SUBTRACT
,
272 VK_DECIMAL
, VK_DIVIDE
, /* FFA8 */
273 VK_NUMPAD0
, VK_NUMPAD1
, VK_NUMPAD2
, VK_NUMPAD3
, VK_NUMPAD4
,
274 VK_NUMPAD5
, VK_NUMPAD6
, VK_NUMPAD7
, /* FFB0 */
275 VK_NUMPAD8
, VK_NUMPAD9
/* FFB8 */
277 static const int keypad_key_scan
[] =
279 0x138, 0x45, /* FF7E */
280 0, 0, 0, 0, 0, 0, 0, 0, /* FF80 */
281 0, 0, 0, 0, 0, 0x11C, 0, 0, /* FF88 */
282 0, 0, 0, 0, 0, 0x47, 0x4B, 0x48, /* FF90 */
283 0x4D, 0x50, 0x49, 0x51, 0x4F, 0x4C, 0x52, 0x53, /* FF98 */
284 0, 0, 0, 0, 0, 0, 0, 0, /* FFA0 */
285 0, 0, 0x37, 0x4E, /*?*/ 0, 0x4A, 0x53, 0x135, /* FFA8 */
286 0x52, 0x4F, 0x50, 0x51, 0x4B, 0x4C, 0x4D, 0x47, /* FFB0 */
287 0x48, 0x49 /* FFB8 */
290 static const int function_key_vkey
[] =
292 VK_F1
, VK_F2
, /* FFBE */
293 VK_F3
, VK_F4
, VK_F5
, VK_F6
, VK_F7
, VK_F8
, VK_F9
, VK_F10
, /* FFC0 */
294 VK_F11
, VK_F12
, VK_F13
, VK_F14
, VK_F15
, VK_F16
/* FFC8 */
296 static const int function_key_scan
[] =
298 0x3B, 0x3C, /* FFBE */
299 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, /* FFC0 */
300 0x57, 0x58, 0, 0, 0, 0 /* FFC8 */
303 static const int modifier_key_vkey
[] =
305 VK_SHIFT
, VK_SHIFT
, VK_CONTROL
, VK_CONTROL
, VK_CAPITAL
, 0, /* FFE1 */
306 VK_MENU
, VK_MENU
, VK_MENU
, VK_MENU
/* FFE7 */
308 static const int modifier_key_scan
[] =
310 0x2A, 0x36, 0x1D, 0x11D, 0x3A, 0, /* FFE1 */
311 0x38, 0x138, 0x38, 0x138 /* FFE7 */
314 /* Returns the Windows virtual key code associated with the X event <e> */
315 static WORD
EVENT_event_to_vkey( XKeyEvent
*e
)
319 TSXLookupString(e
, NULL
, 0, &keysym
, NULL
);
321 if ((keysym
>= 0xFFAE) && (keysym
<= 0xFFB9) && (keysym
!= 0xFFAF)
322 && (e
->state
& NumLockMask
))
323 /* Only the Keypad keys 0-9 and . send different keysyms
324 * depending on the NumLock state */
325 return keypad_key_vkey
[(keysym
& 0xFF) - 0x7E];
327 return keyc2vkey
[e
->keycode
];
330 static BOOL NumState
=FALSE
, CapsState
=FALSE
;
332 /**********************************************************************
333 * KEYBOARD_GenerateMsg
335 * Generate Down+Up messages when NumLock or CapsLock is pressed.
337 * Convention : called with vkey only VK_NUMLOCK or VK_CAPITAL
340 void KEYBOARD_GenerateMsg( WORD vkey
, WORD scan
, int Evtype
, INT event_x
, INT event_y
,
343 BOOL
* State
= (vkey
==VK_NUMLOCK
? &NumState
: &CapsState
);
347 /* The INTERMEDIARY state means : just after a 'press' event, if a 'release' event comes,
348 don't treat it. It's from the same key press. Then the state goes to ON.
349 And from there, a 'release' event will switch off the toggle key. */
351 TRACE(keyboard
,"INTERM : don\'t treat release of toggle key. InputKeyStateTable[%#x] = %#x\n",vkey
,pKeyStateTable
[vkey
]);
354 down
= (vkey
==VK_NUMLOCK
? KEYEVENTF_EXTENDEDKEY
: 0);
355 up
= (vkey
==VK_NUMLOCK
? KEYEVENTF_EXTENDEDKEY
: 0) | KEYEVENTF_KEYUP
;
356 if ( pKeyStateTable
[vkey
] & 0x1 ) /* it was ON */
358 if (Evtype
!=KeyPress
)
360 TRACE(keyboard
,"ON + KeyRelease => generating DOWN and UP messages.\n");
361 KEYBOARD_SendEvent( vkey
, scan
, down
,
362 event_x
, event_y
, event_time
);
363 KEYBOARD_SendEvent( vkey
, scan
, up
,
364 event_x
, event_y
, event_time
);
366 pKeyStateTable
[vkey
] &= ~0x01; /* Toggle state to off. */
369 else /* it was OFF */
370 if (Evtype
==KeyPress
)
372 TRACE(keyboard
,"OFF + Keypress => generating DOWN and UP messages.\n");
373 KEYBOARD_SendEvent( vkey
, scan
, down
,
374 event_x
, event_y
, event_time
);
375 KEYBOARD_SendEvent( vkey
, scan
, up
,
376 event_x
, event_y
, event_time
);
377 *State
=TRUE
; /* Goes to intermediary state before going to ON */
378 pKeyStateTable
[vkey
] |= 0x01; /* Toggle state to on. */
383 /***********************************************************************
384 * KEYBOARD_UpdateOneState
386 * Updates internal state for <vkey>, depending on key <state> under X
389 void KEYBOARD_UpdateOneState ( int vkey
, int state
)
391 /* Do something if internal table state != X state for keycode */
392 if (((pKeyStateTable
[vkey
] & 0x80)!=0) != state
)
394 TRACE(keyboard
,"Adjusting state for vkey %#.2x. State before %#.2x \n",
395 vkey
, pKeyStateTable
[vkey
]);
397 /* Fake key being pressed inside wine */
398 KEYBOARD_SendEvent( vkey
, 0, state
? 0 : KEYEVENTF_KEYUP
,
399 0, 0, GetTickCount() );
401 TRACE(keyboard
,"State after %#.2x \n",pKeyStateTable
[vkey
]);
405 /***********************************************************************
406 * X11DRV_KEYBOARD_UpdateState
408 * Update modifiers state (Ctrl, Alt, Shift)
409 * when window is activated (called by EVENT_FocusIn in event.c)
411 * This handles the case where one uses Ctrl+... Alt+... or Shift+.. to switch
412 * from wine to another application and back.
413 * Toggle keys are handled in HandleEvent. (because XQueryKeymap says nothing
416 void X11DRV_KEYBOARD_UpdateState ( void )
418 /* extract a bit from the char[32] bit suite */
419 #define KeyState(keycode) ((keys_return[keycode/8] & (1<<(keycode%8)))!=0)
421 char keys_return
[32];
423 TRACE(keyboard
,"called\n");
424 if (!TSXQueryKeymap(display
, keys_return
)) {
425 ERR(keyboard
,"Error getting keymap !");
429 /* Adjust the ALT and CONTROL state if any has been changed outside wine */
430 KEYBOARD_UpdateOneState(VK_MENU
, KeyState(kcAlt
));
431 KEYBOARD_UpdateOneState(VK_CONTROL
, KeyState(kcControl
));
432 KEYBOARD_UpdateOneState(VK_SHIFT
, KeyState(kcShift
));
436 /***********************************************************************
437 * X11DRV_KEYBOARD_HandleEvent
439 * Handle a X key event
441 void X11DRV_KEYBOARD_HandleEvent( WND
*pWnd
, XKeyEvent
*event
)
446 WORD vkey
= 0, bScan
;
448 static BOOL force_extended
= FALSE
; /* hack for AltGr translation */
452 INT event_x
= (pWnd
? pWnd
->rectWindow
.left
: 0) + event
->x
;
453 INT event_y
= (pWnd
? pWnd
->rectWindow
.top
: 0) + event
->y
;
454 DWORD event_time
= event
->time
- MSG_WineStartTicks
;
456 /* this allows support for dead keys */
457 if ((event
->keycode
>> 8) == 0x10)
458 event
->keycode
=(event
->keycode
& 0xff);
460 ascii_chars
= TSXLookupString(event
, Str
, 1, &keysym
, &cs
);
462 TRACE(key
, "EVENT_key : state = %X\n", event
->state
);
463 if (keysym
== XK_Mode_switch
)
465 TRACE(key
, "Alt Gr key event received\n");
466 event
->keycode
= kcControl
; /* Simulate Control */
467 X11DRV_KEYBOARD_HandleEvent( pWnd
, event
);
469 event
->keycode
= kcAlt
; /* Simulate Alt */
470 force_extended
= TRUE
;
471 X11DRV_KEYBOARD_HandleEvent( pWnd
, event
);
472 force_extended
= FALSE
;
476 Str
[ascii_chars
] = '\0';
480 ksname
= TSXKeysymToString(keysym
);
483 TRACE(key
, "%s : keysym=%lX (%s), ascii chars=%u / %X / '%s'\n",
484 (event
->type
== KeyPress
) ? "KeyPress" : "KeyRelease",
485 keysym
, ksname
, ascii_chars
, Str
[0] & 0xff, Str
);
488 vkey
= EVENT_event_to_vkey(event
);
489 if (force_extended
) vkey
|= 0x100;
491 TRACE(key
, "keycode 0x%x converted to vkey 0x%x\n",
492 event
->keycode
, vkey
);
499 KEYBOARD_GenerateMsg( VK_NUMLOCK
, 0x45, event
->type
, event_x
, event_y
,
503 TRACE(keyboard
,"Caps Lock event. (type %d). State before : %#.2x\n",event
->type
,pKeyStateTable
[vkey
]);
504 KEYBOARD_GenerateMsg( VK_CAPITAL
, 0x3A, event
->type
, event_x
, event_y
,
506 TRACE(keyboard
,"State after : %#.2x\n",pKeyStateTable
[vkey
]);
509 /* Adjust the NUMLOCK state if it has been changed outside wine */
510 if (!(pKeyStateTable
[VK_NUMLOCK
] & 0x01) != !(event
->state
& NumLockMask
))
512 TRACE(keyboard
,"Adjusting NumLock state. \n");
513 KEYBOARD_GenerateMsg( VK_NUMLOCK
, 0x45, KeyPress
, event_x
, event_y
,
515 KEYBOARD_GenerateMsg( VK_NUMLOCK
, 0x45, KeyRelease
, event_x
, event_y
,
518 /* Adjust the CAPSLOCK state if it has been changed outside wine */
519 if (!(pKeyStateTable
[VK_CAPITAL
] & 0x01) != !(event
->state
& LockMask
))
521 TRACE(keyboard
,"Adjusting Caps Lock state.\n");
522 KEYBOARD_GenerateMsg( VK_CAPITAL
, 0x3A, KeyPress
, event_x
, event_y
,
524 KEYBOARD_GenerateMsg( VK_CAPITAL
, 0x3A, KeyRelease
, event_x
, event_y
,
527 /* Not Num nor Caps : end of intermediary states for both. */
531 bScan
= keyc2scan
[event
->keycode
] & 0xFF;
532 TRACE(key
, "bScan = 0x%02x.\n", bScan
);
535 if ( event
->type
== KeyRelease
) dwFlags
|= KEYEVENTF_KEYUP
;
536 if ( vkey
& 0x100 ) dwFlags
|= KEYEVENTF_EXTENDEDKEY
;
537 if ( force_extended
) dwFlags
|= KEYEVENTF_WINE_FORCEEXTENDED
;
539 KEYBOARD_SendEvent( vkey
& 0xff, bScan
, dwFlags
,
540 event_x
, event_y
, event_time
);
545 /**********************************************************************
546 * X11DRV_KEYBOARD_DetectLayout
548 * Called from X11DRV_KEYBOARD_Init
549 * This routine walks through the defined keyboard layouts and selects
550 * whichever matches most closely.
553 X11DRV_KEYBOARD_DetectLayout (void)
555 unsigned current
, match
, mismatch
, seq
;
556 int score
, keyc
, i
, key
, pkey
, ok
, syms
;
558 const char (*lkey
)[MAIN_LEN
][4];
559 unsigned max_seq
= 0;
560 int max_score
= 0, ismatch
= 0;
564 syms
= keysyms_per_keycode
;
566 WARN (keyboard
, "%d keysyms per keycode not supported, set to 4", syms
);
569 for (current
= 0; main_key_tab
[current
].lang
; current
++) {
570 TRACE (keyboard
, "Attempting to match against layout %04x\n",
571 main_key_tab
[current
].lang
);
576 lkey
= main_key_tab
[current
].key
;
578 for (keyc
= min_keycode
; keyc
<= max_keycode
; keyc
++) {
579 /* get data for keycode from X server */
580 for (i
= 0; i
< syms
; i
++) {
581 keysym
= TSXKeycodeToKeysym (display
, keyc
, i
);
582 /* Allow both one-byte and two-byte national keysyms */
583 if ((keysym
< 0x800) && (keysym
!= ' '))
584 ckey
[i
] = keysym
& 0xFF;
586 ckey
[i
] = KEYBOARD_MapDeadKeysym(keysym
);
590 /* search for a match in layout table */
591 /* right now, we just find an absolute match for defined positions */
592 /* (undefined positions are ignored, so if it's defined as "3#" in */
593 /* the table, it's okay that the X server has "3#£", for example) */
594 /* however, the score will be higher for longer matches */
595 for (key
= 0; key
< MAIN_LEN
; key
++) {
596 for (ok
= 0, i
= 0; (ok
>= 0) && (i
< syms
); i
++) {
597 if ((*lkey
)[key
][i
] && ((*lkey
)[key
][i
] == ckey
[i
]))
599 if ((*lkey
)[key
][i
] && ((*lkey
)[key
][i
] != ckey
[i
]))
607 /* count the matches and mismatches */
610 /* and how much the keycode order matches */
611 if (key
> pkey
) seq
++;
614 TRACE (key
, "mismatch for keycode %d, character %c\n", keyc
,
621 TRACE (keyboard
, "matches=%d, mismatches=%d, score=%d\n",
622 match
, mismatch
, score
);
623 if ((score
> max_score
) ||
624 ((score
== max_score
) && (seq
> max_seq
))) {
625 /* best match so far */
626 kbd_layout
= current
;
632 /* we're done, report results if necessary */
635 "Your keyboard layout was not found!\n"
636 "Instead using closest match (%04x) for scancode mapping.\n"
637 "Please define your layout in windows/x11drv/keyboard.c and submit them\n"
638 "to us for inclusion into future Wine releases.\n"
639 "See documentation/keyboard for more information.\n",
640 main_key_tab
[kbd_layout
].lang
);
642 TRACE (keyboard
, "detected layout is %04x\n", main_key_tab
[kbd_layout
].lang
);
645 /**********************************************************************
646 * X11DRV_KEYBOARD_Init
648 void X11DRV_KEYBOARD_Init(void)
651 XModifierKeymap
*mmp
;
655 WORD scan
, vkey
, OEMvkey
;
656 int keyc
, i
, keyn
, syms
;
657 char ckey
[4]={0,0,0,0};
658 const char (*lkey
)[MAIN_LEN
][4];
660 TSXDisplayKeycodes(display
, &min_keycode
, &max_keycode
);
661 ksp
= TSXGetKeyboardMapping(display
, min_keycode
,
662 max_keycode
+ 1 - min_keycode
, &keysyms_per_keycode
);
663 /* We are only interested in keysyms_per_keycode.
664 There is no need to hold a local copy of the keysyms table */
666 mmp
= TSXGetModifierMapping(display
);
667 kcp
= mmp
->modifiermap
;
668 for (i
= 0; i
< 8; i
+= 1) /* There are 8 modifier keys */
672 for (j
= 0; j
< mmp
->max_keypermod
; j
+= 1, kcp
+= 1)
677 for (k
= 0; k
< keysyms_per_keycode
; k
+= 1)
678 if (TSXKeycodeToKeysym(display
, *kcp
, k
) == XK_Mode_switch
)
681 TRACE(key
, "AltGrMask is %x\n", AltGrMask
);
683 else if (TSXKeycodeToKeysym(display
, *kcp
, k
) == XK_Num_Lock
)
685 NumLockMask
= 1 << i
;
686 TRACE(key
, "NumLockMask is %x\n", NumLockMask
);
690 TSXFreeModifiermap(mmp
);
692 /* Detect the keyboard layout */
693 X11DRV_KEYBOARD_DetectLayout();
694 lkey
= main_key_tab
[kbd_layout
].key
;
695 syms
= (keysyms_per_keycode
> 4) ? 4 : keysyms_per_keycode
;
697 /* Now build two conversion arrays :
698 * keycode -> vkey + scancode + extended
699 * vkey + extended -> keycode */
701 e2
.display
= display
;
704 OEMvkey
= VK_OEM_7
; /* next is available. */
705 for (keyc
= min_keycode
; keyc
<= max_keycode
; keyc
++)
707 e2
.keycode
= (KeyCode
)keyc
;
708 TSXLookupString(&e2
, NULL
, 0, &keysym
, NULL
);
710 if (keysym
) /* otherwise, keycode not used */
712 if ((keysym
>> 8) == 0xFF) /* non-character key */
714 int key
= keysym
& 0xff;
716 if (key
>= 0x08 && key
<= 0x1B) { /* special key */
717 vkey
= special_key_vkey
[key
- 0x08];
718 scan
= special_key_scan
[key
- 0x08];
719 } else if (key
>= 0x50 && key
<= 0x57) { /* cursor key */
720 vkey
= cursor_key_vkey
[key
- 0x50];
721 scan
= cursor_key_scan
[key
- 0x50];
722 } else if (key
>= 0x60 && key
<= 0x6B) { /* miscellaneous key */
723 vkey
= misc_key_vkey
[key
- 0x60];
724 scan
= misc_key_scan
[key
- 0x60];
725 } else if (key
>= 0x7E && key
<= 0xB9) { /* keypad key */
726 vkey
= keypad_key_vkey
[key
- 0x7E];
727 scan
= keypad_key_scan
[key
- 0x7E];
728 } else if (key
>= 0xBE && key
<= 0xCD) { /* function key */
729 vkey
= function_key_vkey
[key
- 0xBE] | 0x100; /* set extended bit */
730 scan
= function_key_scan
[key
- 0xBE];
731 } else if (key
>= 0xE1 && key
<= 0xEA) { /* modifier key */
732 vkey
= modifier_key_vkey
[key
- 0xE1];
733 scan
= modifier_key_scan
[key
- 0xE1];
734 } else if (key
== 0xFF) { /* DEL key */
738 /* set extended bit when necessary */
739 if (scan
& 0x100) vkey
|= 0x100;
740 } else if (keysym
== 0x20) { /* Spacebar */
744 /* we seem to need to search the layout-dependent scancodes */
745 int maxlen
=0,maxval
=-1,ok
;
746 for (i
=0; i
<syms
; i
++) {
747 keysym
= TSXKeycodeToKeysym(display
, keyc
, i
);
748 if ((keysym
<0x800) && (keysym
!=' ')) {
749 ckey
[i
] = keysym
& 0xFF;
751 ckey
[i
] = KEYBOARD_MapDeadKeysym(keysym
);
754 /* find key with longest match streak */
755 for (keyn
=0; keyn
<MAIN_LEN
; keyn
++) {
756 for (ok
=(*lkey
)[keyn
][i
=0]; ok
&&(i
<4); i
++)
757 if ((*lkey
)[keyn
][i
] && (*lkey
)[keyn
][i
]!=ckey
[i
]) ok
=0;
758 if (ok
||(i
>maxlen
)) {
759 maxlen
=i
; maxval
=keyn
;
765 scan
= main_key_scan
[maxval
];
769 /* find a suitable layout-dependent VK code */
770 /* (most Winelib apps ought to be able to work without layout tables!) */
771 for (i
= 0; (i
< keysyms_per_keycode
) && (!vkey
); i
++)
773 keysym
= TSXLookupKeysym(&e2
, i
);
774 if ((keysym
>= VK_0
&& keysym
<= VK_9
)
775 || (keysym
>= VK_A
&& keysym
<= VK_Z
)) {
780 for (i
= 0; (i
< keysyms_per_keycode
) && (!vkey
); i
++)
782 keysym
= TSXLookupKeysym(&e2
, i
);
785 case ';': vkey
= VK_OEM_1
; break;
786 case '/': vkey
= VK_OEM_2
; break;
787 case '`': vkey
= VK_OEM_3
; break;
788 case '[': vkey
= VK_OEM_4
; break;
789 case '\\': vkey
= VK_OEM_5
; break;
790 case ']': vkey
= VK_OEM_6
; break;
791 case '\'': vkey
= VK_OEM_7
; break;
792 case ',': vkey
= VK_OEM_COMMA
; break;
793 case '.': vkey
= VK_OEM_PERIOD
; break;
794 case '-': vkey
= VK_OEM_MINUS
; break;
795 case '+': vkey
= VK_OEM_PLUS
; break;
801 /* Others keys: let's assign OEM virtual key codes in the allowed range,
802 * that is ([0xba,0xc0], [0xdb,0xe4], 0xe6 (given up) et [0xe9,0xf5]) */
805 case 0xc1 : OEMvkey
=0xdb; break;
806 case 0xe5 : OEMvkey
=0xe9; break;
807 case 0xf6 : OEMvkey
=0xf5; WARN(keyboard
,"No more OEM vkey available!\n");
812 if (TRACE_ON(keyboard
))
814 dbg_decl_str(keyboard
, 1024);
816 TRACE(keyboard
, "OEM specific virtual key %X assigned "
817 "to keycode %X:\n", OEMvkey
, e2
.keycode
);
818 for (i
= 0; i
< keysyms_per_keycode
; i
+= 1)
822 keysym
= TSXLookupKeysym(&e2
, i
);
823 ksname
= TSXKeysymToString(keysym
);
826 dsprintf(keyboard
, "%lX (%s) ", keysym
, ksname
);
828 TRACE(keyboard
, "(%s)\n", dbg_str(keyboard
));
832 keyc2vkey
[e2
.keycode
] = vkey
;
833 keyc2scan
[e2
.keycode
] = scan
;
836 /* If some keys still lack scancodes, assign some arbitrary ones to them now */
837 for (scan
= 0x60, keyc
= min_keycode
; keyc
<= max_keycode
; keyc
++)
838 if (keyc2vkey
[keyc
]&&!keyc2scan
[keyc
]) {
840 keysym
= TSXKeycodeToKeysym(display
, keyc
, 0);
841 ksname
= TSXKeysymToString(keysym
);
842 if (!ksname
) ksname
= "NoSymbol";
844 /* should make sure the scancode is unassigned here, but >=0x60 currently always is */
846 TRACE(key
,"assigning scancode %02x to unidentified keycode %02x (%s)\n",scan
,keyc
,ksname
);
847 keyc2scan
[keyc
]=scan
++;
850 /* Now store one keycode for each modifier. Used to simulate keypresses. */
851 kcControl
= TSXKeysymToKeycode(display
, XK_Control_L
);
852 kcAlt
= TSXKeysymToKeycode(display
, XK_Alt_L
);
853 if (!kcAlt
) kcAlt
= TSXKeysymToKeycode(display
, XK_Meta_L
);
854 kcShift
= TSXKeysymToKeycode(display
, XK_Shift_L
);
855 kcNumLock
= TSXKeysymToKeycode(display
, XK_Num_Lock
);
856 kcCapsLock
= TSXKeysymToKeycode(display
, XK_Caps_Lock
);
859 /***********************************************************************
860 * X11DRV_KEYBOARD_VkKeyScan
862 WORD
X11DRV_KEYBOARD_VkKeyScan(CHAR cChar
)
869 /* char->keysym (same for ANSI chars) */
870 keysym
=(unsigned char) cChar
;/* (!) cChar is signed */
871 if (keysym
<=27) keysym
+=0xFF00;/*special chars : return, backspace...*/
873 keycode
= TSXKeysymToKeycode(display
, keysym
); /* keysym -> keycode */
875 { /* It didn't work ... let's try with deadchar code. */
876 keycode
= TSXKeysymToKeycode(display
, keysym
| 0xFE00);
879 TRACE(keyboard
,"VkKeyScan '%c'(%#lx, %lu): got keycode %#.2x\n",
880 cChar
,keysym
,keysym
,keycode
);
884 for (index
=-1, i
=0; (i
<8) && (index
<0); i
++) /* find shift state */
885 if (TSXKeycodeToKeysym(display
,keycode
,i
)==keysym
) index
=i
;
888 WARN(keyboard
,"Keysym %lx not found while parsing the keycode table\n",keysym
); break;
890 case 1 : highbyte
= 0x0100; break;
891 case 2 : highbyte
= 0x0600; break;
892 case 3 : highbyte
= 0x0700; break;
893 default : ERR(keyboard
,"index %d found by XKeycodeToKeysym. please report! \n",index
);
896 index : 0 adds 0x0000
897 index : 1 adds 0x0100 (shift)
898 index : ? adds 0x0200 (ctrl)
899 index : 2 adds 0x0600 (ctrl+alt)
900 index : 3 adds 0x0700 (ctrl+alt+shift)
903 TRACE(keyboard
," ... returning %#.2x\n", keyc2vkey
[keycode
]+highbyte
);
904 return keyc2vkey
[keycode
]+highbyte
; /* keycode -> (keyc2vkey) vkey */
907 /***********************************************************************
908 * X11DRV_KEYBOARD_MapVirtualKey
910 UINT16
X11DRV_KEYBOARD_MapVirtualKey(UINT16 wCode
, UINT16 wMapType
)
912 #define returnMVK(value) { TRACE(keyboard,"returning 0x%x.\n",value); return value; }
914 TRACE(keyboard
,"MapVirtualKey wCode=0x%x wMapType=%d ... \n",
917 case 0: { /* vkey-code to scan-code */
918 /* let's do vkey -> keycode -> scan */
920 for (keyc
=min_keycode
; keyc
<=max_keycode
; keyc
++)
921 if ((keyc2vkey
[keyc
] & 0xFF) == wCode
)
922 returnMVK (keyc2scan
[keyc
] & 0xFF);
923 TRACE(keyboard
,"returning no scan-code.\n");
926 case 1: { /* scan-code to vkey-code */
927 /* let's do scan -> keycode -> vkey */
929 for (keyc
=min_keycode
; keyc
<=max_keycode
; keyc
++)
930 if ((keyc2scan
[keyc
] & 0xFF) == (wCode
& 0xFF))
931 returnMVK (keyc2vkey
[keyc
] & 0xFF);
932 TRACE(keyboard
,"returning no vkey-code.\n");
935 case 2: { /* vkey-code to unshifted ANSI code */
936 /* (was FIXME) : what does unshifted mean ? 'a' or 'A' ? */
937 /* My Windows returns 'A'. */
938 /* let's do vkey -> keycode -> (XLookupString) ansi char */
944 e
.state
= 0; /* unshifted */
947 /* We exit on the first keycode found, to speed up the thing. */
948 for (keyc
=min_keycode
; (keyc
<=max_keycode
) && (!e
.keycode
) ; keyc
++)
949 { /* Find a keycode that could have generated this virtual key */
950 if ((keyc2vkey
[keyc
] & 0xFF) == wCode
)
951 { /* We filter the extended bit, we don't know it */
952 e
.keycode
= keyc
; /* Store it temporarily */
953 if ((EVENT_event_to_vkey(&e
) & 0xFF) != wCode
) {
954 e
.keycode
= 0; /* Wrong one (ex: because of the NumLock
955 state), so set it to 0, we'll find another one */
960 if ((wCode
>=VK_NUMPAD0
) && (wCode
<=VK_NUMPAD9
))
961 e
.keycode
= TSXKeysymToKeycode(e
.display
, wCode
-VK_NUMPAD0
+XK_KP_0
);
963 if (wCode
==VK_DECIMAL
)
964 e
.keycode
= TSXKeysymToKeycode(e
.display
, XK_KP_Decimal
);
968 WARN(keyboard
,"Unknown virtual key %X !!! \n", wCode
);
969 return 0; /* whatever */
971 TRACE(keyboard
,"Found keycode %d (0x%2X)\n",e
.keycode
,e
.keycode
);
973 if (TSXLookupString(&e
, s
, 2, &keysym
, NULL
))
976 TRACE(keyboard
,"returning no ANSI.\n");
980 case 3: /* **NT only** scan-code to vkey-code but distinguish between */
982 FIXME(keyboard
, " stub for NT\n");
985 default: /* reserved */
986 WARN(keyboard
, "Unknown wMapType %d !\n",
993 /***********************************************************************
994 * X11DRV_KEYBOARD_GetKeyNameText
996 INT16
X11DRV_KEYBOARD_GetKeyNameText(LONG lParam
, LPSTR lpBuffer
, INT16 nSize
)
998 int vkey
, ansi
, scanCode
;
1000 scanCode
= lParam
>> 16;
1001 scanCode
&= 0x1ff; /* keep "extended-key" flag with code */
1003 /* FIXME: should use MVK type 3 (NT version that distinguishes right and left */
1004 vkey
= X11DRV_KEYBOARD_MapVirtualKey(scanCode
, 1);
1006 /* handle "don't care" bit (0x02000000) */
1007 if (!(lParam
& 0x02000000)) {
1026 ansi
= X11DRV_KEYBOARD_MapVirtualKey(vkey
, 2);
1027 TRACE(keyboard
, "scan 0x%04x, vkey 0x%04x, ANSI 0x%04x\n",
1028 scanCode
, vkey
, ansi
);
1030 if ((vkey
>= 0x30) && (vkey
<= 0x39) &&
1031 (vkey
>= 0x41) && (vkey
<= 0x5a)) /* Windows VK_* are ANSI codes */
1033 if ((nSize
>= 2) && lpBuffer
)
1035 *lpBuffer
= toupper((char)ansi
);
1043 /* use vkey values to construct names */
1045 FIXME(keyboard
,"(%08lx,%p,%d): unsupported key\n",lParam
,lpBuffer
,nSize
);
1047 if (lpBuffer
&& nSize
)
1052 /***********************************************************************
1053 * X11DRV_KEYBOARD_MapDeadKeysym
1055 static char KEYBOARD_MapDeadKeysym(KeySym keysym
)
1059 /* symbolic ASCII is the same as defined in rfc1345 */
1060 #ifdef XK_dead_tilde
1061 case XK_dead_tilde
:
1063 case 0x1000FE7E : /* Xfree's XK_Dtilde */
1064 return '~'; /* '? */
1065 #ifdef XK_dead_acute
1066 case XK_dead_acute
:
1068 case 0x1000FE27 : /* Xfree's XK_Dacute_accent */
1069 return 0xb4; /* '' */
1070 #ifdef XK_dead_circumflex
1071 case XK_dead_circumflex
:
1073 case 0x1000FE5E : /* Xfree's XK_Dcircumflex_accent */
1074 return '^'; /* '> */
1075 #ifdef XK_dead_grave
1076 case XK_dead_grave
:
1078 case 0x1000FE60 : /* Xfree's XK_Dgrave_accent */
1079 return '`'; /* '! */
1080 #ifdef XK_dead_diaeresis
1081 case XK_dead_diaeresis
:
1083 case 0x1000FE22 : /* Xfree's XK_Ddiaeresis */
1084 return 0xa8; /* ': */
1085 #ifdef XK_dead_cedilla
1086 case XK_dead_cedilla
:
1087 return 0xb8; /* ', */
1089 #ifdef XK_dead_macron
1090 case XK_dead_macron
:
1091 return '-'; /* 'm isn't defined on iso-8859-x */
1093 #ifdef XK_dead_breve
1094 case XK_dead_breve
:
1095 return 0xa2; /* '( */
1097 #ifdef XK_dead_abovedot
1098 case XK_dead_abovedot
:
1099 return 0xff; /* '. */
1101 #ifdef XK_dead_abovering
1102 case XK_dead_abovering
:
1103 return '0'; /* '0 isn't defined on iso-8859-x */
1105 #ifdef XK_dead_doubleacute
1106 case XK_dead_doubleacute
:
1107 return 0xbd; /* '" */
1109 #ifdef XK_dead_caron
1110 case XK_dead_caron
:
1111 return 0xb7; /* '< */
1113 #ifdef XK_dead_ogonek
1114 case XK_dead_ogonek
:
1115 return 0xb2; /* '; */
1117 /* FIXME: I don't know this three.
1120 case XK_dead_voiced_sound :
1122 case XK_dead_semivoiced_sound :
1126 TRACE(keyboard
,"no character for dead keysym 0x%08lx\n",keysym
);
1130 /***********************************************************************
1131 * X11DRV_KEYBOARD_ToAscii
1133 * The ToAscii function translates the specified virtual-key code and keyboard
1134 * state to the corresponding Windows character or characters.
1136 * If the specified key is a dead key, the return value is negative. Otherwise,
1137 * it is one of the following values:
1139 * 0 The specified virtual key has no translation for the current state of the keyboard.
1140 * 1 One Windows character was copied to the buffer.
1141 * 2 Two characters were copied to the buffer. This usually happens when a
1142 * dead-key character (accent or diacritic) stored in the keyboard layout cannot
1143 * be composed with the specified virtual key to form a single character.
1145 * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
1148 INT16
X11DRV_KEYBOARD_ToAscii(
1149 UINT16 virtKey
,UINT16 scanCode
, LPBYTE lpKeyState
,
1150 LPVOID lpChar
, UINT16 flags
)
1154 static XComposeStatus cs
;
1159 /* This happens when doing Alt+letter : a fake 'down arrow' key press
1160 event is generated by windows. Just ignore it. */
1161 TRACE(keyboard
,"scanCode=0, doing nothing\n");
1164 if (scanCode
& 0x8000)
1166 TRACE( keyboard
, "Key UP, doing nothing\n" );
1169 e
.display
= display
;
1172 if (lpKeyState
[VK_SHIFT
] & 0x80)
1173 e
.state
|= ShiftMask
;
1174 if (lpKeyState
[VK_CAPITAL
] & 0x01)
1175 e
.state
|= LockMask
;
1176 if (lpKeyState
[VK_CONTROL
] & 0x80)
1178 if (lpKeyState
[VK_MENU
] & 0x80)
1179 e
.state
|= AltGrMask
;
1181 e
.state
|= ControlMask
;
1183 if (lpKeyState
[VK_NUMLOCK
] & 0x01)
1184 e
.state
|= NumLockMask
;
1185 TRACE(key
, "(%04X, %04X) : faked state = %X\n",
1186 virtKey
, scanCode
, e
.state
);
1187 /* We exit on the first keycode found, to speed up the thing. */
1188 for (keyc
=min_keycode
; (keyc
<=max_keycode
) && (!e
.keycode
) ; keyc
++)
1189 { /* Find a keycode that could have generated this virtual key */
1190 if ((keyc2vkey
[keyc
] & 0xFF) == virtKey
)
1191 { /* We filter the extended bit, we don't know it */
1192 e
.keycode
= keyc
; /* Store it temporarily */
1193 if ((EVENT_event_to_vkey(&e
) & 0xFF) != virtKey
) {
1194 e
.keycode
= 0; /* Wrong one (ex: because of the NumLock
1195 state), so set it to 0, we'll find another one */
1200 if ((virtKey
>=VK_NUMPAD0
) && (virtKey
<=VK_NUMPAD9
))
1201 e
.keycode
= TSXKeysymToKeycode(e
.display
, virtKey
-VK_NUMPAD0
+XK_KP_0
);
1203 if (virtKey
==VK_DECIMAL
)
1204 e
.keycode
= TSXKeysymToKeycode(e
.display
, XK_KP_Decimal
);
1208 WARN(keyboard
,"Unknown virtual key %X !!! \n",virtKey
);
1209 return virtKey
; /* whatever */
1211 else TRACE(keyboard
,"Found keycode %d (0x%2X)\n",e
.keycode
,e
.keycode
);
1213 ret
= TSXLookupString(&e
, (LPVOID
)lpChar
, 2, &keysym
, &cs
);
1218 ((char*)lpChar
)[1] = '\0';
1219 dead_char
= KEYBOARD_MapDeadKeysym(keysym
);
1222 *(char*)lpChar
= dead_char
;
1229 ksname
= TSXKeysymToString(keysym
);
1232 if ((keysym
>> 8) != 0xff)
1234 ERR(keyboard
, "Please report: no char for keysym %04lX (%s) :\n",
1236 ERR(keyboard
, "(virtKey=%X,scanCode=%X,keycode=%X,state=%X)\n",
1237 virtKey
, scanCode
, e
.keycode
, e
.state
);
1241 else { /* ret = 1 */
1242 /* We have a special case to handle : Shift + arrow, shift + home, ...
1243 X returns a char for it, but Windows doesn't. Let's eat it. */
1244 if (!(lpKeyState
[VK_NUMLOCK
] & 0x01) /* NumLock is off */
1245 && (lpKeyState
[VK_SHIFT
] & 0x80) /* Shift is pressed */
1246 && (keysym
>=XK_KP_0
) && (keysym
<=XK_KP_9
))
1253 TRACE(key
, "ToAscii about to return %d with char %x\n",
1254 ret
, *(char*)lpChar
);
1258 /***********************************************************************
1259 * X11DRV_KEYBOARD_GetBeepActive
1261 BOOL
X11DRV_KEYBOARD_GetBeepActive()
1263 XKeyboardState keyboard_state
;
1265 TSXGetKeyboardControl(display
, &keyboard_state
);
1267 return keyboard_state
.bell_percent
!= 0;
1270 /***********************************************************************
1271 * X11DRV_KEYBOARD_SetBeepActive
1273 void X11DRV_KEYBOARD_SetBeepActive(BOOL bActivate
)
1275 XKeyboardControl keyboard_value
;
1278 keyboard_value
.bell_percent
= -1;
1280 keyboard_value
.bell_percent
= 0;
1282 TSXChangeKeyboardControl(display
, KBBellPercent
, &keyboard_value
);
1285 /***********************************************************************
1286 * X11DRV_KEYBOARD_Beep
1288 void X11DRV_KEYBOARD_Beep()
1290 TSXBell(display
, 0);
1293 #endif /* !defined(X_DISPLAY_MISSING) */