winegstreamer: Move the "flip" field to struct wg_parser_stream.
[wine/zf.git] / dlls / dinput / keyboard.c
blob9981372d957ea130ada7fd62163fdf23995b8e18
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, DWORD version)
73 if (!scanCode && version < 0x0800)
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 int dinput_keyboard_hook( 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, This->base.dinput->dwVersion);
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 (dwFlags & DIEDFL_FORCEFEEDBACK)
219 return S_FALSE;
221 if ((dwDevType == 0) ||
222 ((dwDevType == DIDEVTYPE_KEYBOARD) && (version < 0x0800)) ||
223 (((dwDevType == DI8DEVCLASS_KEYBOARD) || (dwDevType == DI8DEVTYPE_KEYBOARD)) && (version >= 0x0800))) {
224 TRACE("Enumerating the Keyboard device\n");
226 fill_keyboard_dideviceinstanceA(lpddi, version, get_keyboard_subtype());
228 return S_OK;
231 return S_FALSE;
234 static HRESULT keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
236 if (id != 0)
237 return E_FAIL;
239 if (dwFlags & DIEDFL_FORCEFEEDBACK)
240 return S_FALSE;
242 if ((dwDevType == 0) ||
243 ((dwDevType == DIDEVTYPE_KEYBOARD) && (version < 0x0800)) ||
244 (((dwDevType == DI8DEVCLASS_KEYBOARD) || (dwDevType == DI8DEVTYPE_KEYBOARD)) && (version >= 0x0800))) {
245 TRACE("Enumerating the Keyboard device\n");
247 fill_keyboard_dideviceinstanceW(lpddi, version, get_keyboard_subtype());
249 return S_OK;
252 return S_FALSE;
255 static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
257 SysKeyboardImpl* newDevice;
258 LPDIDATAFORMAT df = NULL;
259 int i, idx = 0;
261 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboardImpl));
262 newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysKeyboardAvt;
263 newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysKeyboardWvt;
264 newDevice->base.ref = 1;
265 memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
266 newDevice->base.dinput = dinput;
267 InitializeCriticalSection(&newDevice->base.crit);
268 newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysKeyboardImpl*->base.crit");
269 newDevice->subtype = get_keyboard_subtype();
271 /* Create copy of default data format */
272 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIKeyboard.dwSize))) goto failed;
273 memcpy(df, &c_dfDIKeyboard, c_dfDIKeyboard.dwSize);
274 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
276 for (i = 0; i < df->dwNumObjs; i++)
278 char buf[MAX_PATH];
279 BYTE dik_code;
281 if (!GetKeyNameTextA(((i & 0x7f) << 16) | ((i & 0x80) << 17), buf, sizeof(buf)))
282 continue;
284 dik_code = map_dik_code(i, 0, newDevice->subtype, dinput->dwVersion);
285 memcpy(&df->rgodf[idx], &c_dfDIKeyboard.rgodf[dik_code], df->dwObjSize);
286 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(dik_code) | DIDFT_PSHBUTTON;
288 df->dwNumObjs = idx;
290 newDevice->base.data_format.wine_df = df;
291 IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface);
293 return newDevice;
295 failed:
296 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
297 HeapFree(GetProcessHeap(), 0, df);
298 HeapFree(GetProcessHeap(), 0, newDevice);
299 return NULL;
303 static HRESULT keyboarddev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
305 TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
306 *pdev = NULL;
308 if (IsEqualGUID(&GUID_SysKeyboard, rguid)) /* Wine Keyboard */
310 SysKeyboardImpl *This;
312 if (riid == NULL)
313 ;/* nothing */
314 else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
315 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
316 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
317 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
319 unicode = 0;
321 else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
322 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
323 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
324 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
326 unicode = 1;
328 else
330 WARN("no interface\n");
331 return DIERR_NOINTERFACE;
334 This = alloc_device(rguid, dinput);
335 TRACE("Created a Keyboard device (%p)\n", This);
337 if (!This) return DIERR_OUTOFMEMORY;
339 if (unicode)
340 *pdev = &This->base.IDirectInputDevice8W_iface;
341 else
342 *pdev = &This->base.IDirectInputDevice8A_iface;
344 return DI_OK;
347 return DIERR_DEVICENOTREG;
350 const struct dinput_device keyboard_device = {
351 "Wine keyboard driver",
352 keyboarddev_enum_deviceA,
353 keyboarddev_enum_deviceW,
354 keyboarddev_create_device
357 static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr)
359 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
360 TRACE("(%p)->(%d,%p)\n", This, len, ptr);
362 if (!This->base.acquired) return DIERR_NOTACQUIRED;
364 if (len != This->base.data_format.user_df->dwDataSize )
365 return DIERR_INVALIDPARAM;
367 check_dinput_events();
369 EnterCriticalSection(&This->base.crit);
371 if (TRACE_ON(dinput)) {
372 int i;
373 for (i = 0; i < WINE_DINPUT_KEYBOARD_MAX_KEYS; i++) {
374 if (This->DInputKeyState[i] != 0x00)
375 TRACE(" - %02X: %02x\n", i, This->DInputKeyState[i]);
379 fill_DataFormat(ptr, len, This->DInputKeyState, &This->base.data_format);
380 LeaveCriticalSection(&This->base.crit);
382 return DI_OK;
385 static HRESULT WINAPI SysKeyboardAImpl_GetDeviceState(LPDIRECTINPUTDEVICE8A iface, DWORD len, LPVOID ptr)
387 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
388 return SysKeyboardWImpl_GetDeviceState(IDirectInputDevice8W_from_impl(This), len, ptr);
391 /******************************************************************************
392 * GetCapabilities : get the device capabilities
394 static HRESULT WINAPI SysKeyboardWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W iface, LPDIDEVCAPS lpDIDevCaps)
396 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
397 DIDEVCAPS devcaps;
399 TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
401 if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) {
402 WARN("invalid parameter\n");
403 return DIERR_INVALIDPARAM;
406 devcaps.dwSize = lpDIDevCaps->dwSize;
407 devcaps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED;
408 if (This->base.dinput->dwVersion >= 0x0800)
409 devcaps.dwDevType = DI8DEVTYPE_KEYBOARD | (This->subtype << 8);
410 else
411 devcaps.dwDevType = DIDEVTYPE_KEYBOARD | (This->subtype << 8);
412 devcaps.dwAxes = 0;
413 devcaps.dwButtons = This->base.data_format.wine_df->dwNumObjs;
414 devcaps.dwPOVs = 0;
415 devcaps.dwFFSamplePeriod = 0;
416 devcaps.dwFFMinTimeResolution = 0;
417 devcaps.dwFirmwareRevision = 100;
418 devcaps.dwHardwareRevision = 100;
419 devcaps.dwFFDriverVersion = 0;
421 memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize);
423 return DI_OK;
426 static HRESULT WINAPI SysKeyboardAImpl_GetCapabilities(LPDIRECTINPUTDEVICE8A iface, LPDIDEVCAPS lpDIDevCaps)
428 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
429 return SysKeyboardWImpl_GetCapabilities(IDirectInputDevice8W_from_impl(This), lpDIDevCaps);
432 static DWORD map_dik_to_scan(DWORD dik_code, DWORD subtype)
434 if (dik_code == DIK_PAUSE || dik_code == DIK_NUMLOCK) dik_code ^= 0x80;
435 if (subtype == DIDEVTYPEKEYBOARD_JAPAN106)
437 switch (dik_code)
439 case DIK_CIRCUMFLEX:
440 dik_code = 0x0d;
441 break;
442 case DIK_AT:
443 dik_code = 0x1a;
444 break;
445 case DIK_LBRACKET:
446 dik_code = 0x1b;
447 break;
448 case DIK_COLON:
449 dik_code = 0x28;
450 break;
451 case DIK_KANJI:
452 dik_code = 0x29;
453 break;
454 case DIK_RBRACKET:
455 dik_code = 0x2b;
456 break;
457 case DIK_BACKSLASH:
458 dik_code = 0x73;
459 break;
463 return dik_code;
466 /******************************************************************************
467 * GetObjectInfo : get information about a device object such as a button
468 * or axis
470 static HRESULT WINAPI
471 SysKeyboardAImpl_GetObjectInfo(
472 LPDIRECTINPUTDEVICE8A iface,
473 LPDIDEVICEOBJECTINSTANCEA pdidoi,
474 DWORD dwObj,
475 DWORD dwHow)
477 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
478 HRESULT res;
479 LONG scan;
481 res = IDirectInputDevice2AImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
482 if (res != DI_OK) return res;
484 scan = map_dik_to_scan(DIDFT_GETINSTANCE(pdidoi->dwType), This->subtype);
485 if (!GetKeyNameTextA((scan & 0x80) << 17 | (scan & 0x7f) << 16,
486 pdidoi->tszName, sizeof(pdidoi->tszName)))
487 return DIERR_OBJECTNOTFOUND;
489 _dump_OBJECTINSTANCEA(pdidoi);
490 return res;
493 static HRESULT WINAPI SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
494 LPDIDEVICEOBJECTINSTANCEW pdidoi,
495 DWORD dwObj,
496 DWORD dwHow)
498 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
499 HRESULT res;
500 LONG scan;
502 res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
503 if (res != DI_OK) return res;
505 scan = map_dik_to_scan(DIDFT_GETINSTANCE(pdidoi->dwType), This->subtype);
506 if (!GetKeyNameTextW((scan & 0x80) << 17 | (scan & 0x7f) << 16,
507 pdidoi->tszName, ARRAY_SIZE(pdidoi->tszName)))
508 return DIERR_OBJECTNOTFOUND;
510 _dump_OBJECTINSTANCEW(pdidoi);
511 return res;
514 /******************************************************************************
515 * GetDeviceInfo : get information about a device's identity
517 static HRESULT WINAPI SysKeyboardAImpl_GetDeviceInfo(
518 LPDIRECTINPUTDEVICE8A iface,
519 LPDIDEVICEINSTANCEA pdidi)
521 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
522 TRACE("(this=%p,%p)\n", This, pdidi);
524 fill_keyboard_dideviceinstanceA(pdidi, This->base.dinput->dwVersion, This->subtype);
526 return DI_OK;
529 static HRESULT WINAPI SysKeyboardWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
531 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
532 TRACE("(this=%p,%p)\n", This, pdidi);
534 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) {
535 WARN(" dinput3 not supported yet...\n");
536 return DI_OK;
539 fill_keyboard_dideviceinstanceW(pdidi, This->base.dinput->dwVersion, This->subtype);
541 return DI_OK;
544 /******************************************************************************
545 * GetProperty : Retrieves information about the input device.
547 static HRESULT WINAPI SysKeyboardWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface,
548 REFGUID rguid, LPDIPROPHEADER pdiph)
550 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
552 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(rguid), pdiph);
553 _dump_DIPROPHEADER(pdiph);
555 if (!IS_DIPROP(rguid)) return DI_OK;
557 switch (LOWORD(rguid))
559 case (DWORD_PTR)DIPROP_KEYNAME:
561 HRESULT hr;
562 LPDIPROPSTRING ps = (LPDIPROPSTRING)pdiph;
563 DIDEVICEOBJECTINSTANCEW didoi;
565 if (pdiph->dwSize != sizeof(DIPROPSTRING))
566 return DIERR_INVALIDPARAM;
568 didoi.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW);
570 hr = SysKeyboardWImpl_GetObjectInfo(iface, &didoi, ps->diph.dwObj, ps->diph.dwHow);
571 if (hr == DI_OK)
572 memcpy(ps->wsz, didoi.tszName, sizeof(ps->wsz));
573 return hr;
575 case (DWORD_PTR) DIPROP_VIDPID:
576 case (DWORD_PTR) DIPROP_RANGE:
577 return DIERR_UNSUPPORTED;
578 default:
579 return IDirectInputDevice2AImpl_GetProperty( IDirectInputDevice8A_from_impl(This), rguid, pdiph );
581 return DI_OK;
584 static HRESULT WINAPI SysKeyboardAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
585 REFGUID rguid, LPDIPROPHEADER pdiph)
587 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
588 return SysKeyboardWImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
591 static HRESULT WINAPI SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
593 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
594 HRESULT res;
596 TRACE("(%p)\n", This);
598 res = IDirectInputDevice2WImpl_Acquire(iface);
599 if (res == DI_OK)
601 TRACE("clearing keystate\n");
602 memset(This->DInputKeyState, 0, sizeof(This->DInputKeyState));
605 return res;
608 static HRESULT WINAPI SysKeyboardAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
610 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
611 return SysKeyboardWImpl_Acquire(IDirectInputDevice8W_from_impl(This));
614 static HRESULT WINAPI SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
615 LPDIACTIONFORMATW lpdiaf,
616 LPCWSTR lpszUserName,
617 DWORD dwFlags)
619 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
620 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags);
622 return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIKEYBOARD_MASK, &c_dfDIKeyboard);
625 static HRESULT WINAPI SysKeyboardAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
626 LPDIACTIONFORMATA lpdiaf,
627 LPCSTR lpszUserName,
628 DWORD dwFlags)
630 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
631 DIACTIONFORMATW diafW;
632 HRESULT hr;
633 WCHAR *lpszUserNameW = NULL;
634 int username_size;
636 diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiaf->dwNumActions);
637 _copy_diactionformatAtoW(&diafW, lpdiaf);
639 if (lpszUserName != NULL)
641 username_size = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
642 lpszUserNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*username_size);
643 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, lpszUserNameW, username_size);
646 hr = SysKeyboardWImpl_BuildActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
648 _copy_diactionformatWtoA(lpdiaf, &diafW);
649 HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
650 HeapFree(GetProcessHeap(), 0, lpszUserNameW);
652 return hr;
655 static HRESULT WINAPI SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
656 LPDIACTIONFORMATW lpdiaf,
657 LPCWSTR lpszUserName,
658 DWORD dwFlags)
660 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
661 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags);
663 return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIKeyboard);
666 static HRESULT WINAPI SysKeyboardAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
667 LPDIACTIONFORMATA lpdiaf,
668 LPCSTR lpszUserName,
669 DWORD dwFlags)
671 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
672 DIACTIONFORMATW diafW;
673 HRESULT hr;
674 WCHAR *lpszUserNameW = NULL;
675 int username_size;
677 diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiaf->dwNumActions);
678 _copy_diactionformatAtoW(&diafW, lpdiaf);
680 if (lpszUserName != NULL)
682 username_size = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
683 lpszUserNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*username_size);
684 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, lpszUserNameW, username_size);
687 hr = SysKeyboardWImpl_SetActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
689 HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
690 HeapFree(GetProcessHeap(), 0, lpszUserNameW);
692 return hr;
695 static const IDirectInputDevice8AVtbl SysKeyboardAvt =
697 IDirectInputDevice2AImpl_QueryInterface,
698 IDirectInputDevice2AImpl_AddRef,
699 IDirectInputDevice2AImpl_Release,
700 SysKeyboardAImpl_GetCapabilities,
701 IDirectInputDevice2AImpl_EnumObjects,
702 SysKeyboardAImpl_GetProperty,
703 IDirectInputDevice2AImpl_SetProperty,
704 SysKeyboardAImpl_Acquire,
705 IDirectInputDevice2AImpl_Unacquire,
706 SysKeyboardAImpl_GetDeviceState,
707 IDirectInputDevice2AImpl_GetDeviceData,
708 IDirectInputDevice2AImpl_SetDataFormat,
709 IDirectInputDevice2AImpl_SetEventNotification,
710 IDirectInputDevice2AImpl_SetCooperativeLevel,
711 SysKeyboardAImpl_GetObjectInfo,
712 SysKeyboardAImpl_GetDeviceInfo,
713 IDirectInputDevice2AImpl_RunControlPanel,
714 IDirectInputDevice2AImpl_Initialize,
715 IDirectInputDevice2AImpl_CreateEffect,
716 IDirectInputDevice2AImpl_EnumEffects,
717 IDirectInputDevice2AImpl_GetEffectInfo,
718 IDirectInputDevice2AImpl_GetForceFeedbackState,
719 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
720 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
721 IDirectInputDevice2AImpl_Escape,
722 IDirectInputDevice2AImpl_Poll,
723 IDirectInputDevice2AImpl_SendDeviceData,
724 IDirectInputDevice7AImpl_EnumEffectsInFile,
725 IDirectInputDevice7AImpl_WriteEffectToFile,
726 SysKeyboardAImpl_BuildActionMap,
727 SysKeyboardAImpl_SetActionMap,
728 IDirectInputDevice8AImpl_GetImageInfo
731 static const IDirectInputDevice8WVtbl SysKeyboardWvt =
733 IDirectInputDevice2WImpl_QueryInterface,
734 IDirectInputDevice2WImpl_AddRef,
735 IDirectInputDevice2WImpl_Release,
736 SysKeyboardWImpl_GetCapabilities,
737 IDirectInputDevice2WImpl_EnumObjects,
738 SysKeyboardWImpl_GetProperty,
739 IDirectInputDevice2WImpl_SetProperty,
740 SysKeyboardWImpl_Acquire,
741 IDirectInputDevice2WImpl_Unacquire,
742 SysKeyboardWImpl_GetDeviceState,
743 IDirectInputDevice2WImpl_GetDeviceData,
744 IDirectInputDevice2WImpl_SetDataFormat,
745 IDirectInputDevice2WImpl_SetEventNotification,
746 IDirectInputDevice2WImpl_SetCooperativeLevel,
747 SysKeyboardWImpl_GetObjectInfo,
748 SysKeyboardWImpl_GetDeviceInfo,
749 IDirectInputDevice2WImpl_RunControlPanel,
750 IDirectInputDevice2WImpl_Initialize,
751 IDirectInputDevice2WImpl_CreateEffect,
752 IDirectInputDevice2WImpl_EnumEffects,
753 IDirectInputDevice2WImpl_GetEffectInfo,
754 IDirectInputDevice2WImpl_GetForceFeedbackState,
755 IDirectInputDevice2WImpl_SendForceFeedbackCommand,
756 IDirectInputDevice2WImpl_EnumCreatedEffectObjects,
757 IDirectInputDevice2WImpl_Escape,
758 IDirectInputDevice2WImpl_Poll,
759 IDirectInputDevice2WImpl_SendDeviceData,
760 IDirectInputDevice7WImpl_EnumEffectsInFile,
761 IDirectInputDevice7WImpl_WriteEffectToFile,
762 SysKeyboardWImpl_BuildActionMap,
763 SysKeyboardWImpl_SetActionMap,
764 IDirectInputDevice8WImpl_GetImageInfo