2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: keyboard.c,v 1.5 2003/07/20 05:32:19 jimtabor Exp $
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
24 * FILE: subsys/win32k/ntuser/keyboard.c
25 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
27 * 06-06-2001 CSH Created
30 /* INCLUDES ******************************************************************/
32 #include <ddk/ntddk.h>
33 #include <win32k/win32k.h>
34 #include <internal/safe.h>
35 #include <include/guicheck.h>
36 #include <include/msgqueue.h>
37 #include <include/window.h>
38 #include <include/class.h>
39 #include <include/error.h>
40 #include <include/object.h>
41 #include <include/winsta.h>
46 /* FUNCTIONS *****************************************************************/
48 BYTE QueueKeyStateTable
[256];
57 static const struct accent_char accent_chars
[] =
59 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
60 {'`', 'A', '\300'}, {'`', 'a', '\340'},
61 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
62 {'^', 'A', '\302'}, {'^', 'a', '\342'},
63 {'~', 'A', '\303'}, {'~', 'a', '\343'},
64 {'"', 'A', '\304'}, {'"', 'a', '\344'},
65 {'O', 'A', '\305'}, {'o', 'a', '\345'},
66 {'0', 'A', '\305'}, {'0', 'a', '\345'},
67 {'A', 'A', '\305'}, {'a', 'a', '\345'},
68 {'A', 'E', '\306'}, {'a', 'e', '\346'},
69 {',', 'C', '\307'}, {',', 'c', '\347'},
70 {'`', 'E', '\310'}, {'`', 'e', '\350'},
71 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
72 {'^', 'E', '\312'}, {'^', 'e', '\352'},
73 {'"', 'E', '\313'}, {'"', 'e', '\353'},
74 {'`', 'I', '\314'}, {'`', 'i', '\354'},
75 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
76 {'^', 'I', '\316'}, {'^', 'i', '\356'},
77 {'"', 'I', '\317'}, {'"', 'i', '\357'},
78 {'-', 'D', '\320'}, {'-', 'd', '\360'},
79 {'~', 'N', '\321'}, {'~', 'n', '\361'},
80 {'`', 'O', '\322'}, {'`', 'o', '\362'},
81 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
82 {'^', 'O', '\324'}, {'^', 'o', '\364'},
83 {'~', 'O', '\325'}, {'~', 'o', '\365'},
84 {'"', 'O', '\326'}, {'"', 'o', '\366'},
85 {'/', 'O', '\330'}, {'/', 'o', '\370'},
86 {'`', 'U', '\331'}, {'`', 'u', '\371'},
87 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
88 {'^', 'U', '\333'}, {'^', 'u', '\373'},
89 {'"', 'U', '\334'}, {'"', 'u', '\374'},
90 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
91 {'T', 'H', '\336'}, {'t', 'h', '\376'},
92 {'s', 's', '\337'}, {'"', 'y', '\377'},
93 {'s', 'z', '\337'}, {'i', 'j', '\377'},
94 /* iso-8859-2 uses this */
95 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
96 {'<', 'S', '\251'}, {'<', 's', '\271'},
97 {'<', 'T', '\253'}, {'<', 't', '\273'},
98 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
99 {'<', 'C', '\310'}, {'<', 'c', '\350'},
100 {'<', 'E', '\314'}, {'<', 'e', '\354'},
101 {'<', 'D', '\317'}, {'<', 'd', '\357'},
102 {'<', 'N', '\322'}, {'<', 'n', '\362'},
103 {'<', 'R', '\330'}, {'<', 'r', '\370'},
104 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
105 {';', 'E', '\312'}, {';', 'e', '\332'},
106 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
107 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
108 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
109 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
110 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
111 /* collision whith S, from iso-8859-9 !!! */
112 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
113 {',', 'T', '\336'}, {',', 't', '\376'},
114 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
115 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
116 {'/', 'D', '\320'}, {'/', 'd', '\360'},
117 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
118 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
119 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
120 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
121 /* iso-8859-3 uses this */
122 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
123 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
124 {'>', 'J', '\254'}, {'>', 'j', '\274'},
125 {'>', 'C', '\306'}, {'>', 'c', '\346'},
126 {'>', 'G', '\330'}, {'>', 'g', '\370'},
127 {'>', 'S', '\336'}, {'>', 's', '\376'},
128 /* collision whith G( from iso-8859-9 !!! */
129 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
130 {'(', 'U', '\335'}, {'(', 'u', '\375'},
131 /* collision whith I. from iso-8859-3 !!! */
132 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
133 {'.', 'C', '\305'}, {'.', 'c', '\345'},
134 {'.', 'G', '\325'}, {'.', 'g', '\365'},
135 /* iso-8859-4 uses this */
136 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
137 {',', 'L', '\246'}, {',', 'l', '\266'},
138 {',', 'G', '\253'}, {',', 'g', '\273'},
139 {',', 'N', '\321'}, {',', 'n', '\361'},
140 {',', 'K', '\323'}, {',', 'k', '\363'},
141 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
142 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
143 {'-', 'A', '\300'}, {'-', 'a', '\340'},
144 {'-', 'I', '\317'}, {'-', 'i', '\357'},
145 {'-', 'O', '\322'}, {'-', 'o', '\362'},
146 {'-', 'U', '\336'}, {'-', 'u', '\376'},
147 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
148 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
149 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
150 {';', 'U', '\331'}, {';', 'u', '\371'},
151 /* iso-8859-9 uses this */
152 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
153 * whith the same letters on other iso-8859-x (that is they are on
154 * different places :-( ), if you use turkish uncomment these and
155 * comment out the lines in iso-8859-2 and iso-8859-3 sections
156 * FIXME: should be dynamic according to chosen language
157 * if/when Wine has turkish support.
159 /* collision whith G( from iso-8859-3 !!! */
160 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
161 /* collision whith S, from iso-8859-2 !!! */
162 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
163 /* collision whith I. from iso-8859-3 !!! */
164 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
168 ToUnicode(UINT wVirtKey
,
179 NtUserTranslateMessage(LPMSG lpMsg
,
185 static INT dead_char
;
188 if (lpMsg
->message
!= WM_KEYDOWN
&& lpMsg
->message
!= WM_SYSKEYDOWN
)
193 /* FIXME: Should pass current keyboard layout for this thread. */
194 UState
= ToUnicode(lpMsg
->wParam
, HIWORD(lpMsg
->lParam
),
195 QueueKeyStateTable
, wp
, 2, 0);
198 NewMsg
.message
= (lpMsg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
203 if (wp
[0] == ' ') wp
[0] = dead_char
;
204 if (dead_char
== 0xa2) dead_char
= '(';
205 else if (dead_char
== 0xa8) dead_char
= '"';
206 else if (dead_char
== 0xb2) dead_char
= ';';
207 else if (dead_char
== 0xb4) dead_char
= '\'';
208 else if (dead_char
== 0xb7) dead_char
= '<';
209 else if (dead_char
== 0xb8) dead_char
= ',';
210 else if (dead_char
== 0xff) dead_char
= '.';
211 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
213 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
214 (accent_chars
[i
].ac_char
== wp
[0]))
216 wp
[0] = accent_chars
[i
].ac_result
;
221 NewMsg
.hwnd
= lpMsg
->hwnd
;
222 NewMsg
.wParam
= wp
[0];
223 NewMsg
.lParam
= lpMsg
->lParam
;
224 UMsg
= MsqCreateMessage(&NewMsg
);
225 MsqPostMessage(PsGetWin32Thread()->MessageQueue
, UMsg
);
229 else if (UState
== -1)
232 (lpMsg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
233 NewMsg
.hwnd
= lpMsg
->hwnd
;
234 NewMsg
.wParam
= wp
[0];
235 NewMsg
.lParam
= lpMsg
->lParam
;
237 UMsg
= MsqCreateMessage(&NewMsg
);
238 MsqPostMessage(PsGetWin32Thread()->MessageQueue
, UMsg
);
245 NtUserSetFocus(HWND hWnd
)
247 return W32kSetFocusWindow(hWnd
);
258 if (key
>= 'a' && key
<= 'z') key
+= 'A' - 'a';
259 ret
= ((DWORD
)(QueueKeyStateTable
[key
] & 0x80) << 8 ) |
260 (QueueKeyStateTable
[key
] & 0x80) |
261 (QueueKeyStateTable
[key
] & 0x01);
267 NtUserGetKeyboardState(
271 if(!NT_SUCCESS(MmCopyToCaller(lpKeyState
, QueueKeyStateTable
, 256)))
279 NtUserSetKeyboardState(
283 if(! NT_SUCCESS(MmCopyFromCaller(QueueKeyStateTable
, lpKeyState
, 256)))