iphlpapi: Remove unnecessary memcpy from build_udp6_table.
[wine.git] / dlls / dinput / keyboard.c
blob47f28cac52ae5dc64dfc3050c157c1e4718c3051
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 (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 newDevice->base.event_proc = KeyboardCallback;
268 InitializeCriticalSection(&newDevice->base.crit);
269 newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysKeyboardImpl*->base.crit");
270 newDevice->subtype = get_keyboard_subtype();
272 /* Create copy of default data format */
273 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIKeyboard.dwSize))) goto failed;
274 memcpy(df, &c_dfDIKeyboard, c_dfDIKeyboard.dwSize);
275 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
277 for (i = 0; i < df->dwNumObjs; i++)
279 char buf[MAX_PATH];
280 BYTE dik_code;
282 if (!GetKeyNameTextA(((i & 0x7f) << 16) | ((i & 0x80) << 17), buf, sizeof(buf)))
283 continue;
285 dik_code = map_dik_code(i, 0, newDevice->subtype);
286 memcpy(&df->rgodf[idx], &c_dfDIKeyboard.rgodf[dik_code], df->dwObjSize);
287 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(dik_code) | DIDFT_PSHBUTTON;
289 df->dwNumObjs = idx;
291 newDevice->base.data_format.wine_df = df;
292 IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface);
294 EnterCriticalSection(&dinput->crit);
295 list_add_tail(&dinput->devices_list, &newDevice->base.entry);
296 LeaveCriticalSection(&dinput->crit);
298 return newDevice;
300 failed:
301 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
302 HeapFree(GetProcessHeap(), 0, df);
303 HeapFree(GetProcessHeap(), 0, newDevice);
304 return NULL;
308 static HRESULT keyboarddev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
310 TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
311 *pdev = NULL;
313 if (IsEqualGUID(&GUID_SysKeyboard, rguid)) /* Wine Keyboard */
315 SysKeyboardImpl *This;
317 if (riid == NULL)
318 ;/* nothing */
319 else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
320 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
321 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
322 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
324 unicode = 0;
326 else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
327 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
328 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
329 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
331 unicode = 1;
333 else
335 WARN("no interface\n");
336 return DIERR_NOINTERFACE;
339 This = alloc_device(rguid, dinput);
340 TRACE("Created a Keyboard device (%p)\n", This);
342 if (!This) return DIERR_OUTOFMEMORY;
344 if (unicode)
345 *pdev = &This->base.IDirectInputDevice8W_iface;
346 else
347 *pdev = &This->base.IDirectInputDevice8A_iface;
349 return DI_OK;
352 return DIERR_DEVICENOTREG;
355 const struct dinput_device keyboard_device = {
356 "Wine keyboard driver",
357 keyboarddev_enum_deviceA,
358 keyboarddev_enum_deviceW,
359 keyboarddev_create_device
362 static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr)
364 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
365 TRACE("(%p)->(%d,%p)\n", This, len, ptr);
367 if (!This->base.acquired) return DIERR_NOTACQUIRED;
369 if (len != This->base.data_format.user_df->dwDataSize )
370 return DIERR_INVALIDPARAM;
372 check_dinput_events();
374 EnterCriticalSection(&This->base.crit);
376 if (TRACE_ON(dinput)) {
377 int i;
378 for (i = 0; i < WINE_DINPUT_KEYBOARD_MAX_KEYS; i++) {
379 if (This->DInputKeyState[i] != 0x00)
380 TRACE(" - %02X: %02x\n", i, This->DInputKeyState[i]);
384 fill_DataFormat(ptr, len, This->DInputKeyState, &This->base.data_format);
385 LeaveCriticalSection(&This->base.crit);
387 return DI_OK;
390 static HRESULT WINAPI SysKeyboardAImpl_GetDeviceState(LPDIRECTINPUTDEVICE8A iface, DWORD len, LPVOID ptr)
392 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
393 return SysKeyboardWImpl_GetDeviceState(IDirectInputDevice8W_from_impl(This), len, ptr);
396 /******************************************************************************
397 * GetCapabilities : get the device capabilities
399 static HRESULT WINAPI SysKeyboardWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W iface, LPDIDEVCAPS lpDIDevCaps)
401 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
402 DIDEVCAPS devcaps;
404 TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
406 if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) {
407 WARN("invalid parameter\n");
408 return DIERR_INVALIDPARAM;
411 devcaps.dwSize = lpDIDevCaps->dwSize;
412 devcaps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED;
413 if (This->base.dinput->dwVersion >= 0x0800)
414 devcaps.dwDevType = DI8DEVTYPE_KEYBOARD | (This->subtype << 8);
415 else
416 devcaps.dwDevType = DIDEVTYPE_KEYBOARD | (This->subtype << 8);
417 devcaps.dwAxes = 0;
418 devcaps.dwButtons = This->base.data_format.wine_df->dwNumObjs;
419 devcaps.dwPOVs = 0;
420 devcaps.dwFFSamplePeriod = 0;
421 devcaps.dwFFMinTimeResolution = 0;
422 devcaps.dwFirmwareRevision = 100;
423 devcaps.dwHardwareRevision = 100;
424 devcaps.dwFFDriverVersion = 0;
426 memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize);
428 return DI_OK;
431 static HRESULT WINAPI SysKeyboardAImpl_GetCapabilities(LPDIRECTINPUTDEVICE8A iface, LPDIDEVCAPS lpDIDevCaps)
433 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
434 return SysKeyboardWImpl_GetCapabilities(IDirectInputDevice8W_from_impl(This), lpDIDevCaps);
437 static DWORD map_dik_to_scan(DWORD dik_code, DWORD subtype)
439 if (dik_code == DIK_PAUSE || dik_code == DIK_NUMLOCK) dik_code ^= 0x80;
440 if (subtype == DIDEVTYPEKEYBOARD_JAPAN106)
442 switch (dik_code)
444 case DIK_CIRCUMFLEX:
445 dik_code = 0x0d;
446 break;
447 case DIK_AT:
448 dik_code = 0x1a;
449 break;
450 case DIK_LBRACKET:
451 dik_code = 0x1b;
452 break;
453 case DIK_COLON:
454 dik_code = 0x28;
455 break;
456 case DIK_KANJI:
457 dik_code = 0x29;
458 break;
459 case DIK_RBRACKET:
460 dik_code = 0x2b;
461 break;
462 case DIK_BACKSLASH:
463 dik_code = 0x73;
464 break;
468 return dik_code;
471 /******************************************************************************
472 * GetObjectInfo : get information about a device object such as a button
473 * or axis
475 static HRESULT WINAPI
476 SysKeyboardAImpl_GetObjectInfo(
477 LPDIRECTINPUTDEVICE8A iface,
478 LPDIDEVICEOBJECTINSTANCEA pdidoi,
479 DWORD dwObj,
480 DWORD dwHow)
482 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
483 HRESULT res;
484 LONG scan;
486 res = IDirectInputDevice2AImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
487 if (res != DI_OK) return res;
489 scan = map_dik_to_scan(DIDFT_GETINSTANCE(pdidoi->dwType), This->subtype);
490 if (!GetKeyNameTextA((scan & 0x80) << 17 | (scan & 0x7f) << 16,
491 pdidoi->tszName, sizeof(pdidoi->tszName)))
492 return DIERR_OBJECTNOTFOUND;
494 _dump_OBJECTINSTANCEA(pdidoi);
495 return res;
498 static HRESULT WINAPI SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
499 LPDIDEVICEOBJECTINSTANCEW pdidoi,
500 DWORD dwObj,
501 DWORD dwHow)
503 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
504 HRESULT res;
505 LONG scan;
507 res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
508 if (res != DI_OK) return res;
510 scan = map_dik_to_scan(DIDFT_GETINSTANCE(pdidoi->dwType), This->subtype);
511 if (!GetKeyNameTextW((scan & 0x80) << 17 | (scan & 0x7f) << 16,
512 pdidoi->tszName, ARRAY_SIZE(pdidoi->tszName)))
513 return DIERR_OBJECTNOTFOUND;
515 _dump_OBJECTINSTANCEW(pdidoi);
516 return res;
519 /******************************************************************************
520 * GetDeviceInfo : get information about a device's identity
522 static HRESULT WINAPI SysKeyboardAImpl_GetDeviceInfo(
523 LPDIRECTINPUTDEVICE8A iface,
524 LPDIDEVICEINSTANCEA pdidi)
526 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
527 TRACE("(this=%p,%p)\n", This, pdidi);
529 fill_keyboard_dideviceinstanceA(pdidi, This->base.dinput->dwVersion, This->subtype);
531 return DI_OK;
534 static HRESULT WINAPI SysKeyboardWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
536 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
537 TRACE("(this=%p,%p)\n", This, pdidi);
539 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) {
540 WARN(" dinput3 not supported yet...\n");
541 return DI_OK;
544 fill_keyboard_dideviceinstanceW(pdidi, This->base.dinput->dwVersion, This->subtype);
546 return DI_OK;
549 /******************************************************************************
550 * GetProperty : Retrieves information about the input device.
552 static HRESULT WINAPI SysKeyboardWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface,
553 REFGUID rguid, LPDIPROPHEADER pdiph)
555 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
557 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(rguid), pdiph);
558 _dump_DIPROPHEADER(pdiph);
560 if (!IS_DIPROP(rguid)) return DI_OK;
562 switch (LOWORD(rguid))
564 case (DWORD_PTR)DIPROP_KEYNAME:
566 HRESULT hr;
567 LPDIPROPSTRING ps = (LPDIPROPSTRING)pdiph;
568 DIDEVICEOBJECTINSTANCEW didoi;
570 if (pdiph->dwSize != sizeof(DIPROPSTRING))
571 return DIERR_INVALIDPARAM;
573 didoi.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW);
575 hr = SysKeyboardWImpl_GetObjectInfo(iface, &didoi, ps->diph.dwObj, ps->diph.dwHow);
576 if (hr == DI_OK)
577 memcpy(ps->wsz, didoi.tszName, sizeof(ps->wsz));
578 return hr;
580 case (DWORD_PTR) DIPROP_VIDPID:
581 case (DWORD_PTR) DIPROP_RANGE:
582 return DIERR_UNSUPPORTED;
583 default:
584 return IDirectInputDevice2AImpl_GetProperty( IDirectInputDevice8A_from_impl(This), rguid, pdiph );
586 return DI_OK;
589 static HRESULT WINAPI SysKeyboardAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
590 REFGUID rguid, LPDIPROPHEADER pdiph)
592 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
593 return SysKeyboardWImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
596 static HRESULT WINAPI SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
598 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
599 HRESULT res;
601 TRACE("(%p)\n", This);
603 res = IDirectInputDevice2WImpl_Acquire(iface);
604 if (res == DI_OK)
606 TRACE("clearing keystate\n");
607 memset(This->DInputKeyState, 0, sizeof(This->DInputKeyState));
610 return res;
613 static HRESULT WINAPI SysKeyboardAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
615 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
616 return SysKeyboardWImpl_Acquire(IDirectInputDevice8W_from_impl(This));
619 static HRESULT WINAPI SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
620 LPDIACTIONFORMATW lpdiaf,
621 LPCWSTR lpszUserName,
622 DWORD dwFlags)
624 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
625 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags);
627 return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIKEYBOARD_MASK, &c_dfDIKeyboard);
630 static HRESULT WINAPI SysKeyboardAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
631 LPDIACTIONFORMATA lpdiaf,
632 LPCSTR lpszUserName,
633 DWORD dwFlags)
635 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
636 DIACTIONFORMATW diafW;
637 HRESULT hr;
638 WCHAR *lpszUserNameW = NULL;
639 int username_size;
641 diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiaf->dwNumActions);
642 _copy_diactionformatAtoW(&diafW, lpdiaf);
644 if (lpszUserName != NULL)
646 username_size = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
647 lpszUserNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*username_size);
648 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, lpszUserNameW, username_size);
651 hr = SysKeyboardWImpl_BuildActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
653 _copy_diactionformatWtoA(lpdiaf, &diafW);
654 HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
655 HeapFree(GetProcessHeap(), 0, lpszUserNameW);
657 return hr;
660 static HRESULT WINAPI SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
661 LPDIACTIONFORMATW lpdiaf,
662 LPCWSTR lpszUserName,
663 DWORD dwFlags)
665 SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
666 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags);
668 return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIKeyboard);
671 static HRESULT WINAPI SysKeyboardAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
672 LPDIACTIONFORMATA lpdiaf,
673 LPCSTR lpszUserName,
674 DWORD dwFlags)
676 SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
677 DIACTIONFORMATW diafW;
678 HRESULT hr;
679 WCHAR *lpszUserNameW = NULL;
680 int username_size;
682 diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiaf->dwNumActions);
683 _copy_diactionformatAtoW(&diafW, lpdiaf);
685 if (lpszUserName != NULL)
687 username_size = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
688 lpszUserNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*username_size);
689 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, lpszUserNameW, username_size);
692 hr = SysKeyboardWImpl_SetActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
694 HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
695 HeapFree(GetProcessHeap(), 0, lpszUserNameW);
697 return hr;
700 static const IDirectInputDevice8AVtbl SysKeyboardAvt =
702 IDirectInputDevice2AImpl_QueryInterface,
703 IDirectInputDevice2AImpl_AddRef,
704 IDirectInputDevice2AImpl_Release,
705 SysKeyboardAImpl_GetCapabilities,
706 IDirectInputDevice2AImpl_EnumObjects,
707 SysKeyboardAImpl_GetProperty,
708 IDirectInputDevice2AImpl_SetProperty,
709 SysKeyboardAImpl_Acquire,
710 IDirectInputDevice2AImpl_Unacquire,
711 SysKeyboardAImpl_GetDeviceState,
712 IDirectInputDevice2AImpl_GetDeviceData,
713 IDirectInputDevice2AImpl_SetDataFormat,
714 IDirectInputDevice2AImpl_SetEventNotification,
715 IDirectInputDevice2AImpl_SetCooperativeLevel,
716 SysKeyboardAImpl_GetObjectInfo,
717 SysKeyboardAImpl_GetDeviceInfo,
718 IDirectInputDevice2AImpl_RunControlPanel,
719 IDirectInputDevice2AImpl_Initialize,
720 IDirectInputDevice2AImpl_CreateEffect,
721 IDirectInputDevice2AImpl_EnumEffects,
722 IDirectInputDevice2AImpl_GetEffectInfo,
723 IDirectInputDevice2AImpl_GetForceFeedbackState,
724 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
725 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
726 IDirectInputDevice2AImpl_Escape,
727 IDirectInputDevice2AImpl_Poll,
728 IDirectInputDevice2AImpl_SendDeviceData,
729 IDirectInputDevice7AImpl_EnumEffectsInFile,
730 IDirectInputDevice7AImpl_WriteEffectToFile,
731 SysKeyboardAImpl_BuildActionMap,
732 SysKeyboardAImpl_SetActionMap,
733 IDirectInputDevice8AImpl_GetImageInfo
736 static const IDirectInputDevice8WVtbl SysKeyboardWvt =
738 IDirectInputDevice2WImpl_QueryInterface,
739 IDirectInputDevice2WImpl_AddRef,
740 IDirectInputDevice2WImpl_Release,
741 SysKeyboardWImpl_GetCapabilities,
742 IDirectInputDevice2WImpl_EnumObjects,
743 SysKeyboardWImpl_GetProperty,
744 IDirectInputDevice2WImpl_SetProperty,
745 SysKeyboardWImpl_Acquire,
746 IDirectInputDevice2WImpl_Unacquire,
747 SysKeyboardWImpl_GetDeviceState,
748 IDirectInputDevice2WImpl_GetDeviceData,
749 IDirectInputDevice2WImpl_SetDataFormat,
750 IDirectInputDevice2WImpl_SetEventNotification,
751 IDirectInputDevice2WImpl_SetCooperativeLevel,
752 SysKeyboardWImpl_GetObjectInfo,
753 SysKeyboardWImpl_GetDeviceInfo,
754 IDirectInputDevice2WImpl_RunControlPanel,
755 IDirectInputDevice2WImpl_Initialize,
756 IDirectInputDevice2WImpl_CreateEffect,
757 IDirectInputDevice2WImpl_EnumEffects,
758 IDirectInputDevice2WImpl_GetEffectInfo,
759 IDirectInputDevice2WImpl_GetForceFeedbackState,
760 IDirectInputDevice2WImpl_SendForceFeedbackCommand,
761 IDirectInputDevice2WImpl_EnumCreatedEffectObjects,
762 IDirectInputDevice2WImpl_Escape,
763 IDirectInputDevice2WImpl_Poll,
764 IDirectInputDevice2WImpl_SendDeviceData,
765 IDirectInputDevice7WImpl_EnumEffectsInFile,
766 IDirectInputDevice7WImpl_WriteEffectToFile,
767 SysKeyboardWImpl_BuildActionMap,
768 SysKeyboardWImpl_SetActionMap,
769 IDirectInputDevice8WImpl_GetImageInfo