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