294ccfd755f290ce7352603b3a643e85a175f5af
[reactos.git] / reactos / dll / directx / wine / dinput / keyboard.c
1 /* DirectInput Keyboard device
2 *
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
6 * Copyright 2005 Raphael Junqueira
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #include "dinput_private.h"
24
25 #define WINE_DINPUT_KEYBOARD_MAX_KEYS 256
26
27 static const IDirectInputDevice8AVtbl SysKeyboardAvt;
28 static const IDirectInputDevice8WVtbl SysKeyboardWvt;
29
30 typedef struct SysKeyboardImpl SysKeyboardImpl;
31 struct SysKeyboardImpl
32 {
33 struct IDirectInputDeviceImpl base;
34 BYTE DInputKeyState[WINE_DINPUT_KEYBOARD_MAX_KEYS];
35 };
36
37 static inline SysKeyboardImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface)
38 {
39 return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface), SysKeyboardImpl, base);
40 }
41 static inline SysKeyboardImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
42 {
43 return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), SysKeyboardImpl, base);
44 }
45 static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(SysKeyboardImpl *This)
46 {
47 return &This->base.IDirectInputDevice8A_iface;
48 }
49 static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(SysKeyboardImpl *This)
50 {
51 return &This->base.IDirectInputDevice8W_iface;
52 }
53
54 static BYTE map_dik_code(DWORD scanCode, DWORD vkCode)
55 {
56 static const BYTE asciiCodes[] =
57 {/*32*/ DIK_SPACE,0,0,0,0,0,0,DIK_APOSTROPHE,
58 /*40*/ 0,0,0,0,DIK_COMMA,DIK_MINUS,DIK_PERIOD,DIK_SLASH,
59 /*48*/ DIK_0,DIK_1,DIK_2,DIK_3,DIK_4,DIK_5,DIK_6,DIK_7,
60 /*56*/ DIK_8,DIK_9,DIK_COLON,DIK_SEMICOLON,0,DIK_EQUALS,0,0,
61 /*64*/ DIK_AT,DIK_A,DIK_B,DIK_C,DIK_D,DIK_E,DIK_F,DIK_G,
62 /*72*/ DIK_H,DIK_I,DIK_J,DIK_K,DIK_L,DIK_M,DIK_N,DIK_O,
63 /*80*/ DIK_P,DIK_Q,DIK_R,DIK_S,DIK_T,DIK_U,DIK_V,DIK_W,
64 /*88*/ DIK_X,DIK_Y,DIK_Z,DIK_LBRACKET,0,DIK_RBRACKET,DIK_CIRCUMFLEX,DIK_UNDERLINE} /*95*/ ;
65
66 BYTE out_code = 0;
67 WCHAR c = MapVirtualKeyW(vkCode,MAPVK_VK_TO_CHAR);
68
69 if (c > 31 && c < 96)
70 out_code = asciiCodes[c - 32];
71
72 if (out_code == 0)
73 out_code = scanCode;
74
75 return out_code;
76 }
77
78 static int KeyboardCallback( LPDIRECTINPUTDEVICE8A iface, WPARAM wparam, LPARAM lparam )
79 {
80 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
81 int dik_code, ret = This->base.dwCoopLevel & DISCL_EXCLUSIVE;
82 KBDLLHOOKSTRUCT *hook = (KBDLLHOOKSTRUCT *)lparam;
83 BYTE new_diks;
84
85 if (wparam != WM_KEYDOWN && wparam != WM_KEYUP &&
86 wparam != WM_SYSKEYDOWN && wparam != WM_SYSKEYUP)
87 return 0;
88
89 TRACE("(%p) %ld,%ld\n", iface, wparam, lparam);
90
91 switch (hook->vkCode)
92 {
93 /* R-Shift is special - it is an extended key with separate scan code */
94 case VK_RSHIFT : dik_code = DIK_RSHIFT; break;
95 case VK_PAUSE : dik_code = DIK_PAUSE; break;
96 case VK_NUMLOCK : dik_code = DIK_NUMLOCK; break;
97 case VK_SUBTRACT: dik_code = DIK_SUBTRACT; break;
98 default:
99 dik_code = map_dik_code(hook->scanCode & 0xff, hook->vkCode);
100 if (hook->flags & LLKHF_EXTENDED) dik_code |= 0x80;
101 }
102 new_diks = hook->flags & LLKHF_UP ? 0 : 0x80;
103
104 /* returns now if key event already known */
105 if (new_diks == This->DInputKeyState[dik_code])
106 return ret;
107
108 This->DInputKeyState[dik_code] = new_diks;
109 TRACE(" setting %02X to %02X\n", dik_code, This->DInputKeyState[dik_code]);
110
111 EnterCriticalSection(&This->base.crit);
112 queue_event(iface, DIDFT_MAKEINSTANCE(dik_code) | DIDFT_PSHBUTTON,
113 new_diks, GetCurrentTime(), This->base.dinput->evsequence++);
114 LeaveCriticalSection(&This->base.crit);
115
116 return ret;
117 }
118
119 const GUID DInput_Wine_Keyboard_GUID = { /* 0ab8648a-7735-11d2-8c73-71df54a96441 */
120 0x0ab8648a, 0x7735, 0x11d2, {0x8c, 0x73, 0x71, 0xdf, 0x54, 0xa9, 0x64, 0x41}
121 };
122
123 static void fill_keyboard_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version) {
124 DWORD dwSize;
125 DIDEVICEINSTANCEA ddi;
126
127 dwSize = lpddi->dwSize;
128
129 TRACE("%d %p\n", dwSize, lpddi);
130
131 memset(lpddi, 0, dwSize);
132 memset(&ddi, 0, sizeof(ddi));
133
134 ddi.dwSize = dwSize;
135 ddi.guidInstance = GUID_SysKeyboard;/* DInput's GUID */
136 ddi.guidProduct = DInput_Wine_Keyboard_GUID; /* Vendor's GUID */
137 if (version >= 0x0800)
138 ddi.dwDevType = DI8DEVTYPE_KEYBOARD | (DI8DEVTYPEKEYBOARD_UNKNOWN << 8);
139 else
140 ddi.dwDevType = DIDEVTYPE_KEYBOARD | (DIDEVTYPEKEYBOARD_UNKNOWN << 8);
141 strcpy(ddi.tszInstanceName, "Keyboard");
142 strcpy(ddi.tszProductName, "Wine Keyboard");
143
144 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
145 }
146
147 static void fill_keyboard_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version) {
148 DWORD dwSize;
149 DIDEVICEINSTANCEW ddi;
150
151 dwSize = lpddi->dwSize;
152
153 TRACE("%d %p\n", dwSize, lpddi);
154
155 memset(lpddi, 0, dwSize);
156 memset(&ddi, 0, sizeof(ddi));
157
158 ddi.dwSize = dwSize;
159 ddi.guidInstance = GUID_SysKeyboard;/* DInput's GUID */
160 ddi.guidProduct = DInput_Wine_Keyboard_GUID; /* Vendor's GUID */
161 if (version >= 0x0800)
162 ddi.dwDevType = DI8DEVTYPE_KEYBOARD | (DI8DEVTYPEKEYBOARD_UNKNOWN << 8);
163 else
164 ddi.dwDevType = DIDEVTYPE_KEYBOARD | (DIDEVTYPEKEYBOARD_UNKNOWN << 8);
165 MultiByteToWideChar(CP_ACP, 0, "Keyboard", -1, ddi.tszInstanceName, MAX_PATH);
166 MultiByteToWideChar(CP_ACP, 0, "Wine Keyboard", -1, ddi.tszProductName, MAX_PATH);
167
168 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
169 }
170
171 static HRESULT keyboarddev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
172 {
173 if (id != 0)
174 return E_FAIL;
175
176 if ((dwDevType == 0) ||
177 ((dwDevType == DIDEVTYPE_KEYBOARD) && (version < 0x0800)) ||
178 (((dwDevType == DI8DEVCLASS_KEYBOARD) || (dwDevType == DI8DEVTYPE_KEYBOARD)) && (version >= 0x0800))) {
179 TRACE("Enumerating the Keyboard device\n");
180
181 fill_keyboard_dideviceinstanceA(lpddi, version);
182
183 return S_OK;
184 }
185
186 return S_FALSE;
187 }
188
189 static HRESULT keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
190 {
191 if (id != 0)
192 return E_FAIL;
193
194 if ((dwDevType == 0) ||
195 ((dwDevType == DIDEVTYPE_KEYBOARD) && (version < 0x0800)) ||
196 (((dwDevType == DI8DEVCLASS_KEYBOARD) || (dwDevType == DI8DEVTYPE_KEYBOARD)) && (version >= 0x0800))) {
197 TRACE("Enumerating the Keyboard device\n");
198
199 fill_keyboard_dideviceinstanceW(lpddi, version);
200
201 return S_OK;
202 }
203
204 return S_FALSE;
205 }
206
207 static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
208 {
209 SysKeyboardImpl* newDevice;
210 LPDIDATAFORMAT df = NULL;
211 int i, idx = 0;
212
213 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboardImpl));
214 newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysKeyboardAvt;
215 newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysKeyboardWvt;
216 newDevice->base.ref = 1;
217 memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
218 newDevice->base.dinput = dinput;
219 newDevice->base.event_proc = KeyboardCallback;
220 InitializeCriticalSection(&newDevice->base.crit);
221 newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysKeyboardImpl*->base.crit");
222
223 /* Create copy of default data format */
224 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIKeyboard.dwSize))) goto failed;
225 memcpy(df, &c_dfDIKeyboard, c_dfDIKeyboard.dwSize);
226 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
227
228 for (i = 0; i < df->dwNumObjs; i++)
229 {
230 char buf[MAX_PATH];
231
232 if (!GetKeyNameTextA(((i & 0x7f) << 16) | ((i & 0x80) << 17), buf, sizeof(buf)))
233 continue;
234
235 memcpy(&df->rgodf[idx], &c_dfDIKeyboard.rgodf[i], df->dwObjSize);
236 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
237 }
238 df->dwNumObjs = idx;
239
240 newDevice->base.data_format.wine_df = df;
241 IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface);
242
243 EnterCriticalSection(&dinput->crit);
244 list_add_tail(&dinput->devices_list, &newDevice->base.entry);
245 LeaveCriticalSection(&dinput->crit);
246
247 return newDevice;
248
249 failed:
250 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
251 HeapFree(GetProcessHeap(), 0, df);
252 HeapFree(GetProcessHeap(), 0, newDevice);
253 return NULL;
254 }
255
256
257 static HRESULT keyboarddev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
258 {
259 TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
260 *pdev = NULL;
261
262 if (IsEqualGUID(&GUID_SysKeyboard, rguid) || /* Generic Keyboard */
263 IsEqualGUID(&DInput_Wine_Keyboard_GUID, rguid)) /* Wine Keyboard */
264 {
265 SysKeyboardImpl *This;
266
267 if (riid == NULL)
268 ;/* nothing */
269 else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
270 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
271 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
272 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
273 {
274 unicode = 0;
275 }
276 else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
277 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
278 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
279 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
280 {
281 unicode = 1;
282 }
283 else
284 {
285 WARN("no interface\n");
286 return DIERR_NOINTERFACE;
287 }
288
289 This = alloc_device(rguid, dinput);
290 TRACE("Created a Keyboard device (%p)\n", This);
291
292 if (!This) return DIERR_OUTOFMEMORY;
293
294 if (unicode)
295 *pdev = &This->base.IDirectInputDevice8W_iface;
296 else
297 *pdev = &This->base.IDirectInputDevice8A_iface;
298
299 return DI_OK;
300 }
301
302 return DIERR_DEVICENOTREG;
303 }
304
305 const struct dinput_device keyboard_device = {
306 "Wine keyboard driver",
307 keyboarddev_enum_deviceA,
308 keyboarddev_enum_deviceW,
309 keyboarddev_create_device
310 };
311
312 static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr)
313 {
314 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
315 TRACE("(%p)->(%d,%p)\n", This, len, ptr);
316
317 if (!This->base.acquired) return DIERR_NOTACQUIRED;
318
319 if (len != This->base.data_format.user_df->dwDataSize )
320 return DIERR_INVALIDPARAM;
321
322 #ifndef __REACTOS__
323 __wine_check_for_events( QS_ALLINPUT );
324 #endif
325
326 EnterCriticalSection(&This->base.crit);
327
328 if (TRACE_ON(dinput)) {
329 int i;
330 for (i = 0; i < WINE_DINPUT_KEYBOARD_MAX_KEYS; i++) {
331 if (This->DInputKeyState[i] != 0x00)
332 TRACE(" - %02X: %02x\n", i, This->DInputKeyState[i]);
333 }
334 }
335
336 fill_DataFormat(ptr, len, This->DInputKeyState, &This->base.data_format);
337 LeaveCriticalSection(&This->base.crit);
338
339 return DI_OK;
340 }
341
342 static HRESULT WINAPI SysKeyboardAImpl_GetDeviceState(LPDIRECTINPUTDEVICE8A iface, DWORD len, LPVOID ptr)
343 {
344 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
345 return SysKeyboardWImpl_GetDeviceState(IDirectInputDevice8W_from_impl(This), len, ptr);
346 }
347
348 /******************************************************************************
349 * GetCapabilities : get the device capabilities
350 */
351 static HRESULT WINAPI SysKeyboardWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W iface, LPDIDEVCAPS lpDIDevCaps)
352 {
353 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
354 DIDEVCAPS devcaps;
355
356 TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
357
358 if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) {
359 WARN("invalid parameter\n");
360 return DIERR_INVALIDPARAM;
361 }
362
363 devcaps.dwSize = lpDIDevCaps->dwSize;
364 devcaps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED;
365 if (This->base.dinput->dwVersion >= 0x0800)
366 devcaps.dwDevType = DI8DEVTYPE_KEYBOARD | (DI8DEVTYPEKEYBOARD_PCENH << 8);
367 else
368 devcaps.dwDevType = DIDEVTYPE_KEYBOARD | (DIDEVTYPEKEYBOARD_PCENH << 8);
369 devcaps.dwAxes = 0;
370 devcaps.dwButtons = This->base.data_format.wine_df->dwNumObjs;
371 devcaps.dwPOVs = 0;
372 devcaps.dwFFSamplePeriod = 0;
373 devcaps.dwFFMinTimeResolution = 0;
374 devcaps.dwFirmwareRevision = 100;
375 devcaps.dwHardwareRevision = 100;
376 devcaps.dwFFDriverVersion = 0;
377
378 memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize);
379
380 return DI_OK;
381 }
382
383 static HRESULT WINAPI SysKeyboardAImpl_GetCapabilities(LPDIRECTINPUTDEVICE8A iface, LPDIDEVCAPS lpDIDevCaps)
384 {
385 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
386 return SysKeyboardWImpl_GetCapabilities(IDirectInputDevice8W_from_impl(This), lpDIDevCaps);
387 }
388
389 /******************************************************************************
390 * GetObjectInfo : get information about a device object such as a button
391 * or axis
392 */
393 static HRESULT WINAPI
394 SysKeyboardAImpl_GetObjectInfo(
395 LPDIRECTINPUTDEVICE8A iface,
396 LPDIDEVICEOBJECTINSTANCEA pdidoi,
397 DWORD dwObj,
398 DWORD dwHow)
399 {
400 HRESULT res;
401 LONG scan;
402
403 res = IDirectInputDevice2AImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
404 if (res != DI_OK) return res;
405
406 scan = DIDFT_GETINSTANCE(pdidoi->dwType);
407 if (scan == DIK_PAUSE || scan == DIK_NUMLOCK) scan ^= 0x80;
408 if (!GetKeyNameTextA((scan & 0x80) << 17 | (scan & 0x7f) << 16,
409 pdidoi->tszName, sizeof(pdidoi->tszName)))
410 return DIERR_OBJECTNOTFOUND;
411
412 _dump_OBJECTINSTANCEA(pdidoi);
413 return res;
414 }
415
416 static HRESULT WINAPI SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
417 LPDIDEVICEOBJECTINSTANCEW pdidoi,
418 DWORD dwObj,
419 DWORD dwHow)
420 {
421 HRESULT res;
422 LONG scan;
423
424 res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
425 if (res != DI_OK) return res;
426
427 scan = DIDFT_GETINSTANCE(pdidoi->dwType);
428 if (scan == DIK_PAUSE || scan == DIK_NUMLOCK) scan ^= 0x80;
429 if (!GetKeyNameTextW((scan & 0x80) << 17 | (scan & 0x7f) << 16,
430 pdidoi->tszName, sizeof(pdidoi->tszName)/sizeof(pdidoi->tszName[0])))
431 return DIERR_OBJECTNOTFOUND;
432
433 _dump_OBJECTINSTANCEW(pdidoi);
434 return res;
435 }
436
437 /******************************************************************************
438 * GetDeviceInfo : get information about a device's identity
439 */
440 static HRESULT WINAPI SysKeyboardAImpl_GetDeviceInfo(
441 LPDIRECTINPUTDEVICE8A iface,
442 LPDIDEVICEINSTANCEA pdidi)
443 {
444 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
445 TRACE("(this=%p,%p)\n", This, pdidi);
446
447 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)) {
448 WARN(" dinput3 not supported yet...\n");
449 return DI_OK;
450 }
451
452 fill_keyboard_dideviceinstanceA(pdidi, This->base.dinput->dwVersion);
453
454 return DI_OK;
455 }
456
457 static HRESULT WINAPI SysKeyboardWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
458 {
459 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
460 TRACE("(this=%p,%p)\n", This, pdidi);
461
462 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) {
463 WARN(" dinput3 not supported yet...\n");
464 return DI_OK;
465 }
466
467 fill_keyboard_dideviceinstanceW(pdidi, This->base.dinput->dwVersion);
468
469 return DI_OK;
470 }
471
472 /******************************************************************************
473 * GetProperty : Retrieves information about the input device.
474 */
475 static HRESULT WINAPI SysKeyboardWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface,
476 REFGUID rguid, LPDIPROPHEADER pdiph)
477 {
478 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
479
480 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
481 _dump_DIPROPHEADER(pdiph);
482
483 if (!IS_DIPROP(rguid)) return DI_OK;
484
485 switch (LOWORD(rguid))
486 {
487 case (DWORD_PTR)DIPROP_KEYNAME:
488 {
489 HRESULT hr;
490 LPDIPROPSTRING ps = (LPDIPROPSTRING)pdiph;
491 DIDEVICEOBJECTINSTANCEW didoi;
492
493 if (pdiph->dwSize != sizeof(DIPROPSTRING))
494 return DIERR_INVALIDPARAM;
495
496 didoi.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW);
497
498 hr = SysKeyboardWImpl_GetObjectInfo(iface, &didoi, ps->diph.dwObj, ps->diph.dwHow);
499 if (hr == DI_OK)
500 memcpy(ps->wsz, didoi.tszName, sizeof(ps->wsz));
501 return hr;
502 }
503 case (DWORD_PTR) DIPROP_RANGE:
504 return DIERR_UNSUPPORTED;
505 default:
506 return IDirectInputDevice2AImpl_GetProperty( IDirectInputDevice8A_from_impl(This), rguid, pdiph );
507 }
508 return DI_OK;
509 }
510
511 static HRESULT WINAPI SysKeyboardAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
512 REFGUID rguid, LPDIPROPHEADER pdiph)
513 {
514 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
515 return SysKeyboardWImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
516 }
517
518 static HRESULT WINAPI SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
519 {
520 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
521 HRESULT res;
522
523 TRACE("(%p)\n", This);
524
525 res = IDirectInputDevice2WImpl_Acquire(iface);
526 if (res == DI_OK)
527 {
528 TRACE("clearing keystate\n");
529 memset(This->DInputKeyState, 0, sizeof(This->DInputKeyState));
530 }
531
532 return res;
533 }
534
535 static HRESULT WINAPI SysKeyboardAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
536 {
537 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
538 return SysKeyboardWImpl_Acquire(IDirectInputDevice8W_from_impl(This));
539 }
540
541 static HRESULT WINAPI SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
542 LPDIACTIONFORMATW lpdiaf,
543 LPCWSTR lpszUserName,
544 DWORD dwFlags)
545 {
546 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
547
548 return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIKEYBOARD_MASK, &c_dfDIKeyboard);
549 }
550
551 static HRESULT WINAPI SysKeyboardAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
552 LPDIACTIONFORMATA lpdiaf,
553 LPCSTR lpszUserName,
554 DWORD dwFlags)
555 {
556 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
557 DIACTIONFORMATW diafW;
558 HRESULT hr;
559 WCHAR *lpszUserNameW = NULL;
560 int username_size;
561
562 diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiaf->dwNumActions);
563 _copy_diactionformatAtoW(&diafW, lpdiaf);
564
565 if (lpszUserName != NULL)
566 {
567 username_size = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
568 lpszUserNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*username_size);
569 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, lpszUserNameW, username_size);
570 }
571
572 hr = SysKeyboardWImpl_BuildActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
573
574 _copy_diactionformatWtoA(lpdiaf, &diafW);
575 HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
576 HeapFree(GetProcessHeap(), 0, lpszUserNameW);
577
578 return hr;
579 }
580
581 static HRESULT WINAPI SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
582 LPDIACTIONFORMATW lpdiaf,
583 LPCWSTR lpszUserName,
584 DWORD dwFlags)
585 {
586 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
587
588 return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIKeyboard);
589 }
590
591 static HRESULT WINAPI SysKeyboardAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
592 LPDIACTIONFORMATA lpdiaf,
593 LPCSTR lpszUserName,
594 DWORD dwFlags)
595 {
596 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
597 DIACTIONFORMATW diafW;
598 HRESULT hr;
599 WCHAR *lpszUserNameW = NULL;
600 int username_size;
601
602 diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiaf->dwNumActions);
603 _copy_diactionformatAtoW(&diafW, lpdiaf);
604
605 if (lpszUserName != NULL)
606 {
607 username_size = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
608 lpszUserNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*username_size);
609 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, lpszUserNameW, username_size);
610 }
611
612 hr = SysKeyboardWImpl_SetActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
613
614 HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
615 HeapFree(GetProcessHeap(), 0, lpszUserNameW);
616
617 return hr;
618 }
619
620 static const IDirectInputDevice8AVtbl SysKeyboardAvt =
621 {
622 IDirectInputDevice2AImpl_QueryInterface,
623 IDirectInputDevice2AImpl_AddRef,
624 IDirectInputDevice2AImpl_Release,
625 SysKeyboardAImpl_GetCapabilities,
626 IDirectInputDevice2AImpl_EnumObjects,
627 SysKeyboardAImpl_GetProperty,
628 IDirectInputDevice2AImpl_SetProperty,
629 SysKeyboardAImpl_Acquire,
630 IDirectInputDevice2AImpl_Unacquire,
631 SysKeyboardAImpl_GetDeviceState,
632 IDirectInputDevice2AImpl_GetDeviceData,
633 IDirectInputDevice2AImpl_SetDataFormat,
634 IDirectInputDevice2AImpl_SetEventNotification,
635 IDirectInputDevice2AImpl_SetCooperativeLevel,
636 SysKeyboardAImpl_GetObjectInfo,
637 SysKeyboardAImpl_GetDeviceInfo,
638 IDirectInputDevice2AImpl_RunControlPanel,
639 IDirectInputDevice2AImpl_Initialize,
640 IDirectInputDevice2AImpl_CreateEffect,
641 IDirectInputDevice2AImpl_EnumEffects,
642 IDirectInputDevice2AImpl_GetEffectInfo,
643 IDirectInputDevice2AImpl_GetForceFeedbackState,
644 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
645 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
646 IDirectInputDevice2AImpl_Escape,
647 IDirectInputDevice2AImpl_Poll,
648 IDirectInputDevice2AImpl_SendDeviceData,
649 IDirectInputDevice7AImpl_EnumEffectsInFile,
650 IDirectInputDevice7AImpl_WriteEffectToFile,
651 SysKeyboardAImpl_BuildActionMap,
652 SysKeyboardAImpl_SetActionMap,
653 IDirectInputDevice8AImpl_GetImageInfo
654 };
655
656 static const IDirectInputDevice8WVtbl SysKeyboardWvt =
657 {
658 IDirectInputDevice2WImpl_QueryInterface,
659 IDirectInputDevice2WImpl_AddRef,
660 IDirectInputDevice2WImpl_Release,
661 SysKeyboardWImpl_GetCapabilities,
662 IDirectInputDevice2WImpl_EnumObjects,
663 SysKeyboardWImpl_GetProperty,
664 IDirectInputDevice2WImpl_SetProperty,
665 SysKeyboardWImpl_Acquire,
666 IDirectInputDevice2WImpl_Unacquire,
667 SysKeyboardWImpl_GetDeviceState,
668 IDirectInputDevice2WImpl_GetDeviceData,
669 IDirectInputDevice2WImpl_SetDataFormat,
670 IDirectInputDevice2WImpl_SetEventNotification,
671 IDirectInputDevice2WImpl_SetCooperativeLevel,
672 SysKeyboardWImpl_GetObjectInfo,
673 SysKeyboardWImpl_GetDeviceInfo,
674 IDirectInputDevice2WImpl_RunControlPanel,
675 IDirectInputDevice2WImpl_Initialize,
676 IDirectInputDevice2WImpl_CreateEffect,
677 IDirectInputDevice2WImpl_EnumEffects,
678 IDirectInputDevice2WImpl_GetEffectInfo,
679 IDirectInputDevice2WImpl_GetForceFeedbackState,
680 IDirectInputDevice2WImpl_SendForceFeedbackCommand,
681 IDirectInputDevice2WImpl_EnumCreatedEffectObjects,
682 IDirectInputDevice2WImpl_Escape,
683 IDirectInputDevice2WImpl_Poll,
684 IDirectInputDevice2WImpl_SendDeviceData,
685 IDirectInputDevice7WImpl_EnumEffectsInFile,
686 IDirectInputDevice7WImpl_WriteEffectToFile,
687 SysKeyboardWImpl_BuildActionMap,
688 SysKeyboardWImpl_SetActionMap,
689 IDirectInputDevice8WImpl_GetImageInfo
690 };