ntoskrnl.exe/tests: Fix path buffer allocation size.
[wine.git] / dlls / dinput / keyboard.c
blob642d0c0beb8252eb5f9f6e532c0b979586305d48
1 /* DirectInput Keyboard device
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
6 * Copyright 2005 Raphael Junqueira
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.
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.
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
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdarg.h>
27 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "winerror.h"
32 #include "dinput.h"
34 #include "dinput_private.h"
35 #include "device_private.h"
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
41 #define WINE_DINPUT_KEYBOARD_MAX_KEYS 256
43 static const IDirectInputDevice8AVtbl SysKeyboardAvt;
44 static const IDirectInputDevice8WVtbl SysKeyboardWvt;
46 typedef struct SysKeyboardImpl SysKeyboardImpl;
47 struct SysKeyboardImpl
49 struct IDirectInputDeviceImpl base;
50 BYTE DInputKeyState[WINE_DINPUT_KEYBOARD_MAX_KEYS];
51 DWORD subtype;
54 static inline SysKeyboardImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface)
56 return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface), SysKeyboardImpl, base);
58 static inline SysKeyboardImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
60 return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), SysKeyboardImpl, base);
62 static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(SysKeyboardImpl *This)
64 return &This->base.IDirectInputDevice8A_iface;
66 static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(SysKeyboardImpl *This)
68 return &This->base.IDirectInputDevice8W_iface;
71 static BYTE map_dik_code(DWORD scanCode, DWORD vkCode, DWORD subType)
73 if (!scanCode)
74 scanCode = MapVirtualKeyW(vkCode, MAPVK_VK_TO_VSC);
76 if (subType == DIDEVTYPEKEYBOARD_JAPAN106)
78 switch (scanCode)
80 case 0x0d: /* ^ */
81 scanCode = DIK_CIRCUMFLEX;
82 break;
83 case 0x1a: /* @ */
84 scanCode = DIK_AT;
85 break;
86 case 0x1b: /* [ */
87 scanCode = DIK_LBRACKET;
88 break;
89 case 0x28: /* : */
90 scanCode = DIK_COLON;
91 break;
92 case 0x29: /* Hankaku/Zenkaku */
93 scanCode = DIK_KANJI;
94 break;
95 case 0x2b: /* ] */
96 scanCode = DIK_RBRACKET;
97 break;
98 case 0x73: /* \ */
99 scanCode = DIK_BACKSLASH;
100 break;
103 return scanCode;
106 static int KeyboardCallback( LPDIRECTINPUTDEVICE8A iface, WPARAM wparam, LPARAM lparam )
108 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
109 int dik_code, ret = This->base.dwCoopLevel & DISCL_EXCLUSIVE;
110 KBDLLHOOKSTRUCT *hook = (KBDLLHOOKSTRUCT *)lparam;
111 BYTE new_diks;
113 if (wparam != WM_KEYDOWN && wparam != WM_KEYUP &&
114 wparam != WM_SYSKEYDOWN && wparam != WM_SYSKEYUP)
115 return 0;
117 TRACE("(%p) wp %08lx, lp %08lx, vk %02x, scan %02x\n",
118 iface, wparam, lparam, hook->vkCode, hook->scanCode);
120 switch (hook->vkCode)
122 /* R-Shift is special - it is an extended key with separate scan code */
123 case VK_RSHIFT : dik_code = DIK_RSHIFT; break;
124 case VK_PAUSE : dik_code = DIK_PAUSE; break;
125 case VK_NUMLOCK : dik_code = DIK_NUMLOCK; break;
126 case VK_SUBTRACT: dik_code = DIK_SUBTRACT; break;
127 default:
128 dik_code = map_dik_code(hook->scanCode & 0xff, hook->vkCode, This->subtype);
129 if (hook->flags & LLKHF_EXTENDED) dik_code |= 0x80;
131 new_diks = hook->flags & LLKHF_UP ? 0 : 0x80;
133 /* returns now if key event already known */
134 if (new_diks == This->DInputKeyState[dik_code])
135 return ret;
137 This->DInputKeyState[dik_code] = new_diks;
138 TRACE(" setting %02X to %02X\n", dik_code, This->DInputKeyState[dik_code]);
140 EnterCriticalSection(&This->base.crit);
141 queue_event(iface, DIDFT_MAKEINSTANCE(dik_code) | DIDFT_PSHBUTTON,
142 new_diks, GetCurrentTime(), This->base.dinput->evsequence++);
143 LeaveCriticalSection(&This->base.crit);
145 return ret;
148 static DWORD get_keyboard_subtype(void)
150 DWORD kbd_type, kbd_subtype, dev_subtype;
151 kbd_type = GetKeyboardType(0);
152 kbd_subtype = GetKeyboardType(1);
154 if (kbd_type == 4 || (kbd_type == 7 && kbd_subtype == 0))
155 dev_subtype = DIDEVTYPEKEYBOARD_PCENH;
156 else if (kbd_type == 7 && kbd_subtype == 2)
157 dev_subtype = DIDEVTYPEKEYBOARD_JAPAN106;
158 else {
159 FIXME("Unknown keyboard type=%u, subtype=%u\n", kbd_type, kbd_subtype);
160 dev_subtype = DIDEVTYPEKEYBOARD_PCENH;
162 return dev_subtype;
165 static void fill_keyboard_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version, DWORD subtype) {
166 DWORD dwSize;
167 DIDEVICEINSTANCEA ddi;
169 dwSize = lpddi->dwSize;
171 TRACE("%d %p\n", dwSize, lpddi);
173 memset(lpddi, 0, dwSize);
174 memset(&ddi, 0, sizeof(ddi));
176 ddi.dwSize = dwSize;
177 ddi.guidInstance = GUID_SysKeyboard;/* DInput's GUID */
178 ddi.guidProduct = GUID_SysKeyboard;
179 if (version >= 0x0800)
180 ddi.dwDevType = DI8DEVTYPE_KEYBOARD | (subtype << 8);
181 else
182 ddi.dwDevType = DIDEVTYPE_KEYBOARD | (subtype << 8);
183 strcpy(ddi.tszInstanceName, "Keyboard");
184 strcpy(ddi.tszProductName, "Wine Keyboard");
186 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
189 static void fill_keyboard_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version, DWORD subtype) {
190 DWORD dwSize;
191 DIDEVICEINSTANCEW ddi;
193 dwSize = lpddi->dwSize;
195 TRACE("%d %p\n", dwSize, lpddi);
197 memset(lpddi, 0, dwSize);
198 memset(&ddi, 0, sizeof(ddi));
200 ddi.dwSize = dwSize;
201 ddi.guidInstance = GUID_SysKeyboard;/* DInput's GUID */
202 ddi.guidProduct = GUID_SysKeyboard;
203 if (version >= 0x0800)
204 ddi.dwDevType = DI8DEVTYPE_KEYBOARD | (subtype << 8);
205 else
206 ddi.dwDevType = DIDEVTYPE_KEYBOARD | (subtype << 8);
207 MultiByteToWideChar(CP_ACP, 0, "Keyboard", -1, ddi.tszInstanceName, MAX_PATH);
208 MultiByteToWideChar(CP_ACP, 0, "Wine Keyboard", -1, ddi.tszProductName, MAX_PATH);
210 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
213 static HRESULT keyboarddev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
215 if (id != 0)
216 return E_FAIL;
218 if ((dwDevType == 0) ||
219 ((dwDevType == DIDEVTYPE_KEYBOARD) && (version < 0x0800)) ||
220 (((dwDevType == DI8DEVCLASS_KEYBOARD) || (dwDevType == DI8DEVTYPE_KEYBOARD)) && (version >= 0x0800))) {
221 TRACE("Enumerating the Keyboard device\n");
223 fill_keyboard_dideviceinstanceA(lpddi, version, get_keyboard_subtype());
225 return S_OK;
228 return S_FALSE;
231 static HRESULT keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
233 if (id != 0)
234 return E_FAIL;
236 if ((dwDevType == 0) ||
237 ((dwDevType == DIDEVTYPE_KEYBOARD) && (version < 0x0800)) ||
238 (((dwDevType == DI8DEVCLASS_KEYBOARD) || (dwDevType == DI8DEVTYPE_KEYBOARD)) && (version >= 0x0800))) {
239 TRACE("Enumerating the Keyboard device\n");
241 fill_keyboard_dideviceinstanceW(lpddi, version, get_keyboard_subtype());
243 return S_OK;
246 return S_FALSE;
249 static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
251 SysKeyboardImpl* newDevice;
252 LPDIDATAFORMAT df = NULL;
253 int i, idx = 0;
255 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboardImpl));
256 newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysKeyboardAvt;
257 newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysKeyboardWvt;
258 newDevice->base.ref = 1;
259 memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
260 newDevice->base.dinput = dinput;
261 newDevice->base.event_proc = KeyboardCallback;
262 InitializeCriticalSection(&newDevice->base.crit);
263 newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysKeyboardImpl*->base.crit");
264 newDevice->subtype = get_keyboard_subtype();
266 /* Create copy of default data format */
267 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIKeyboard.dwSize))) goto failed;
268 memcpy(df, &c_dfDIKeyboard, c_dfDIKeyboard.dwSize);
269 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
271 for (i = 0; i < df->dwNumObjs; i++)
273 char buf[MAX_PATH];
274 BYTE dik_code;
276 if (!GetKeyNameTextA(((i & 0x7f) << 16) | ((i & 0x80) << 17), buf, sizeof(buf)))
277 continue;
279 dik_code = map_dik_code(i, 0, newDevice->subtype);
280 memcpy(&df->rgodf[idx], &c_dfDIKeyboard.rgodf[dik_code], df->dwObjSize);
281 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(dik_code) | DIDFT_PSHBUTTON;
283 df->dwNumObjs = idx;
285 newDevice->base.data_format.wine_df = df;
286 IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface);
288 EnterCriticalSection(&dinput->crit);
289 list_add_tail(&dinput->devices_list, &newDevice->base.entry);
290 LeaveCriticalSection(&dinput->crit);
292 return newDevice;
294 failed:
295 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
296 HeapFree(GetProcessHeap(), 0, df);
297 HeapFree(GetProcessHeap(), 0, newDevice);
298 return NULL;
302 static HRESULT keyboarddev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
304 TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
305 *pdev = NULL;
307 if (IsEqualGUID(&GUID_SysKeyboard, rguid)) /* Wine Keyboard */
309 SysKeyboardImpl *This;
311 if (riid == NULL)
312 ;/* nothing */
313 else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
314 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
315 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
316 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
318 unicode = 0;
320 else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
321 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
322 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
323 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
325 unicode = 1;
327 else
329 WARN("no interface\n");
330 return DIERR_NOINTERFACE;
333 This = alloc_device(rguid, dinput);
334 TRACE("Created a Keyboard device (%p)\n", This);
336 if (!This) return DIERR_OUTOFMEMORY;
338 if (unicode)
339 *pdev = &This->base.IDirectInputDevice8W_iface;
340 else
341 *pdev = &This->base.IDirectInputDevice8A_iface;
343 return DI_OK;
346 return DIERR_DEVICENOTREG;
349 const struct dinput_device keyboard_device = {
350 "Wine keyboard driver",
351 keyboarddev_enum_deviceA,
352 keyboarddev_enum_deviceW,
353 keyboarddev_create_device
356 static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr)
358 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
359 TRACE("(%p)->(%d,%p)\n", This, len, ptr);
361 if (!This->base.acquired) return DIERR_NOTACQUIRED;
363 if (len != This->base.data_format.user_df->dwDataSize )
364 return DIERR_INVALIDPARAM;
366 check_dinput_events();
368 EnterCriticalSection(&This->base.crit);
370 if (TRACE_ON(dinput)) {
371 int i;
372 for (i = 0; i < WINE_DINPUT_KEYBOARD_MAX_KEYS; i++) {
373 if (This->DInputKeyState[i] != 0x00)
374 TRACE(" - %02X: %02x\n", i, This->DInputKeyState[i]);
378 fill_DataFormat(ptr, len, This->DInputKeyState, &This->base.data_format);
379 LeaveCriticalSection(&This->base.crit);
381 return DI_OK;
384 static HRESULT WINAPI SysKeyboardAImpl_GetDeviceState(LPDIRECTINPUTDEVICE8A iface, DWORD len, LPVOID ptr)
386 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
387 return SysKeyboardWImpl_GetDeviceState(IDirectInputDevice8W_from_impl(This), len, ptr);
390 /******************************************************************************
391 * GetCapabilities : get the device capabilities
393 static HRESULT WINAPI SysKeyboardWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W iface, LPDIDEVCAPS lpDIDevCaps)
395 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
396 DIDEVCAPS devcaps;
398 TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
400 if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) {
401 WARN("invalid parameter\n");
402 return DIERR_INVALIDPARAM;
405 devcaps.dwSize = lpDIDevCaps->dwSize;
406 devcaps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED;
407 if (This->base.dinput->dwVersion >= 0x0800)
408 devcaps.dwDevType = DI8DEVTYPE_KEYBOARD | (This->subtype << 8);
409 else
410 devcaps.dwDevType = DIDEVTYPE_KEYBOARD | (This->subtype << 8);
411 devcaps.dwAxes = 0;
412 devcaps.dwButtons = This->base.data_format.wine_df->dwNumObjs;
413 devcaps.dwPOVs = 0;
414 devcaps.dwFFSamplePeriod = 0;
415 devcaps.dwFFMinTimeResolution = 0;
416 devcaps.dwFirmwareRevision = 100;
417 devcaps.dwHardwareRevision = 100;
418 devcaps.dwFFDriverVersion = 0;
420 memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize);
422 return DI_OK;
425 static HRESULT WINAPI SysKeyboardAImpl_GetCapabilities(LPDIRECTINPUTDEVICE8A iface, LPDIDEVCAPS lpDIDevCaps)
427 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
428 return SysKeyboardWImpl_GetCapabilities(IDirectInputDevice8W_from_impl(This), lpDIDevCaps);
431 static DWORD map_dik_to_scan(DWORD dik_code, DWORD subtype)
433 if (dik_code == DIK_PAUSE || dik_code == DIK_NUMLOCK) dik_code ^= 0x80;
434 if (subtype == DIDEVTYPEKEYBOARD_JAPAN106)
436 switch (dik_code)
438 case DIK_CIRCUMFLEX:
439 dik_code = 0x0d;
440 break;
441 case DIK_AT:
442 dik_code = 0x1a;
443 break;
444 case DIK_LBRACKET:
445 dik_code = 0x1b;
446 break;
447 case DIK_COLON:
448 dik_code = 0x28;
449 break;
450 case DIK_KANJI:
451 dik_code = 0x29;
452 break;
453 case DIK_RBRACKET:
454 dik_code = 0x2b;
455 break;
456 case DIK_BACKSLASH:
457 dik_code = 0x73;
458 break;
462 return dik_code;
465 /******************************************************************************
466 * GetObjectInfo : get information about a device object such as a button
467 * or axis
469 static HRESULT WINAPI
470 SysKeyboardAImpl_GetObjectInfo(
471 LPDIRECTINPUTDEVICE8A iface,
472 LPDIDEVICEOBJECTINSTANCEA pdidoi,
473 DWORD dwObj,
474 DWORD dwHow)
476 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
477 HRESULT res;
478 LONG scan;
480 res = IDirectInputDevice2AImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
481 if (res != DI_OK) return res;
483 scan = map_dik_to_scan(DIDFT_GETINSTANCE(pdidoi->dwType), This->subtype);
484 if (!GetKeyNameTextA((scan & 0x80) << 17 | (scan & 0x7f) << 16,
485 pdidoi->tszName, sizeof(pdidoi->tszName)))
486 return DIERR_OBJECTNOTFOUND;
488 _dump_OBJECTINSTANCEA(pdidoi);
489 return res;
492 static HRESULT WINAPI SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
493 LPDIDEVICEOBJECTINSTANCEW pdidoi,
494 DWORD dwObj,
495 DWORD dwHow)
497 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
498 HRESULT res;
499 LONG scan;
501 res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
502 if (res != DI_OK) return res;
504 scan = map_dik_to_scan(DIDFT_GETINSTANCE(pdidoi->dwType), This->subtype);
505 if (!GetKeyNameTextW((scan & 0x80) << 17 | (scan & 0x7f) << 16,
506 pdidoi->tszName, ARRAY_SIZE(pdidoi->tszName)))
507 return DIERR_OBJECTNOTFOUND;
509 _dump_OBJECTINSTANCEW(pdidoi);
510 return res;
513 /******************************************************************************
514 * GetDeviceInfo : get information about a device's identity
516 static HRESULT WINAPI SysKeyboardAImpl_GetDeviceInfo(
517 LPDIRECTINPUTDEVICE8A iface,
518 LPDIDEVICEINSTANCEA pdidi)
520 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
521 TRACE("(this=%p,%p)\n", This, pdidi);
523 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)) {
524 WARN(" dinput3 not supported yet...\n");
525 return DI_OK;
528 fill_keyboard_dideviceinstanceA(pdidi, This->base.dinput->dwVersion, This->subtype);
530 return DI_OK;
533 static HRESULT WINAPI SysKeyboardWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
535 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
536 TRACE("(this=%p,%p)\n", This, pdidi);
538 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) {
539 WARN(" dinput3 not supported yet...\n");
540 return DI_OK;
543 fill_keyboard_dideviceinstanceW(pdidi, This->base.dinput->dwVersion, This->subtype);
545 return DI_OK;
548 /******************************************************************************
549 * GetProperty : Retrieves information about the input device.
551 static HRESULT WINAPI SysKeyboardWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface,
552 REFGUID rguid, LPDIPROPHEADER pdiph)
554 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
556 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
557 _dump_DIPROPHEADER(pdiph);
559 if (!IS_DIPROP(rguid)) return DI_OK;
561 switch (LOWORD(rguid))
563 case (DWORD_PTR)DIPROP_KEYNAME:
565 HRESULT hr;
566 LPDIPROPSTRING ps = (LPDIPROPSTRING)pdiph;
567 DIDEVICEOBJECTINSTANCEW didoi;
569 if (pdiph->dwSize != sizeof(DIPROPSTRING))
570 return DIERR_INVALIDPARAM;
572 didoi.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW);
574 hr = SysKeyboardWImpl_GetObjectInfo(iface, &didoi, ps->diph.dwObj, ps->diph.dwHow);
575 if (hr == DI_OK)
576 memcpy(ps->wsz, didoi.tszName, sizeof(ps->wsz));
577 return hr;
579 case (DWORD_PTR) DIPROP_RANGE:
580 return DIERR_UNSUPPORTED;
581 default:
582 return IDirectInputDevice2AImpl_GetProperty( IDirectInputDevice8A_from_impl(This), rguid, pdiph );
584 return DI_OK;
587 static HRESULT WINAPI SysKeyboardAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
588 REFGUID rguid, LPDIPROPHEADER pdiph)
590 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
591 return SysKeyboardWImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
594 static HRESULT WINAPI SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
596 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
597 HRESULT res;
599 TRACE("(%p)\n", This);
601 res = IDirectInputDevice2WImpl_Acquire(iface);
602 if (res == DI_OK)
604 TRACE("clearing keystate\n");
605 memset(This->DInputKeyState, 0, sizeof(This->DInputKeyState));
608 return res;
611 static HRESULT WINAPI SysKeyboardAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
613 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
614 return SysKeyboardWImpl_Acquire(IDirectInputDevice8W_from_impl(This));
617 static HRESULT WINAPI SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
618 LPDIACTIONFORMATW lpdiaf,
619 LPCWSTR lpszUserName,
620 DWORD dwFlags)
622 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
624 return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIKEYBOARD_MASK, &c_dfDIKeyboard);
627 static HRESULT WINAPI SysKeyboardAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
628 LPDIACTIONFORMATA lpdiaf,
629 LPCSTR lpszUserName,
630 DWORD dwFlags)
632 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
633 DIACTIONFORMATW diafW;
634 HRESULT hr;
635 WCHAR *lpszUserNameW = NULL;
636 int username_size;
638 diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiaf->dwNumActions);
639 _copy_diactionformatAtoW(&diafW, lpdiaf);
641 if (lpszUserName != NULL)
643 username_size = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
644 lpszUserNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*username_size);
645 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, lpszUserNameW, username_size);
648 hr = SysKeyboardWImpl_BuildActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
650 _copy_diactionformatWtoA(lpdiaf, &diafW);
651 HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
652 HeapFree(GetProcessHeap(), 0, lpszUserNameW);
654 return hr;
657 static HRESULT WINAPI SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
658 LPDIACTIONFORMATW lpdiaf,
659 LPCWSTR lpszUserName,
660 DWORD dwFlags)
662 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
664 return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIKeyboard);
667 static HRESULT WINAPI SysKeyboardAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
668 LPDIACTIONFORMATA lpdiaf,
669 LPCSTR lpszUserName,
670 DWORD dwFlags)
672 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
673 DIACTIONFORMATW diafW;
674 HRESULT hr;
675 WCHAR *lpszUserNameW = NULL;
676 int username_size;
678 diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiaf->dwNumActions);
679 _copy_diactionformatAtoW(&diafW, lpdiaf);
681 if (lpszUserName != NULL)
683 username_size = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
684 lpszUserNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*username_size);
685 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, lpszUserNameW, username_size);
688 hr = SysKeyboardWImpl_SetActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
690 HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
691 HeapFree(GetProcessHeap(), 0, lpszUserNameW);
693 return hr;
696 static const IDirectInputDevice8AVtbl SysKeyboardAvt =
698 IDirectInputDevice2AImpl_QueryInterface,
699 IDirectInputDevice2AImpl_AddRef,
700 IDirectInputDevice2AImpl_Release,
701 SysKeyboardAImpl_GetCapabilities,
702 IDirectInputDevice2AImpl_EnumObjects,
703 SysKeyboardAImpl_GetProperty,
704 IDirectInputDevice2AImpl_SetProperty,
705 SysKeyboardAImpl_Acquire,
706 IDirectInputDevice2AImpl_Unacquire,
707 SysKeyboardAImpl_GetDeviceState,
708 IDirectInputDevice2AImpl_GetDeviceData,
709 IDirectInputDevice2AImpl_SetDataFormat,
710 IDirectInputDevice2AImpl_SetEventNotification,
711 IDirectInputDevice2AImpl_SetCooperativeLevel,
712 SysKeyboardAImpl_GetObjectInfo,
713 SysKeyboardAImpl_GetDeviceInfo,
714 IDirectInputDevice2AImpl_RunControlPanel,
715 IDirectInputDevice2AImpl_Initialize,
716 IDirectInputDevice2AImpl_CreateEffect,
717 IDirectInputDevice2AImpl_EnumEffects,
718 IDirectInputDevice2AImpl_GetEffectInfo,
719 IDirectInputDevice2AImpl_GetForceFeedbackState,
720 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
721 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
722 IDirectInputDevice2AImpl_Escape,
723 IDirectInputDevice2AImpl_Poll,
724 IDirectInputDevice2AImpl_SendDeviceData,
725 IDirectInputDevice7AImpl_EnumEffectsInFile,
726 IDirectInputDevice7AImpl_WriteEffectToFile,
727 SysKeyboardAImpl_BuildActionMap,
728 SysKeyboardAImpl_SetActionMap,
729 IDirectInputDevice8AImpl_GetImageInfo
732 static const IDirectInputDevice8WVtbl SysKeyboardWvt =
734 IDirectInputDevice2WImpl_QueryInterface,
735 IDirectInputDevice2WImpl_AddRef,
736 IDirectInputDevice2WImpl_Release,
737 SysKeyboardWImpl_GetCapabilities,
738 IDirectInputDevice2WImpl_EnumObjects,
739 SysKeyboardWImpl_GetProperty,
740 IDirectInputDevice2WImpl_SetProperty,
741 SysKeyboardWImpl_Acquire,
742 IDirectInputDevice2WImpl_Unacquire,
743 SysKeyboardWImpl_GetDeviceState,
744 IDirectInputDevice2WImpl_GetDeviceData,
745 IDirectInputDevice2WImpl_SetDataFormat,
746 IDirectInputDevice2WImpl_SetEventNotification,
747 IDirectInputDevice2WImpl_SetCooperativeLevel,
748 SysKeyboardWImpl_GetObjectInfo,
749 SysKeyboardWImpl_GetDeviceInfo,
750 IDirectInputDevice2WImpl_RunControlPanel,
751 IDirectInputDevice2WImpl_Initialize,
752 IDirectInputDevice2WImpl_CreateEffect,
753 IDirectInputDevice2WImpl_EnumEffects,
754 IDirectInputDevice2WImpl_GetEffectInfo,
755 IDirectInputDevice2WImpl_GetForceFeedbackState,
756 IDirectInputDevice2WImpl_SendForceFeedbackCommand,
757 IDirectInputDevice2WImpl_EnumCreatedEffectObjects,
758 IDirectInputDevice2WImpl_Escape,
759 IDirectInputDevice2WImpl_Poll,
760 IDirectInputDevice2WImpl_SendDeviceData,
761 IDirectInputDevice7WImpl_EnumEffectsInFile,
762 IDirectInputDevice7WImpl_WriteEffectToFile,
763 SysKeyboardWImpl_BuildActionMap,
764 SysKeyboardWImpl_SetActionMap,
765 IDirectInputDevice8WImpl_GetImageInfo