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
24 #include "wine/port.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
];
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
)
74 scanCode
= MapVirtualKeyW(vkCode
, MAPVK_VK_TO_VSC
);
76 if (subType
== DIDEVTYPEKEYBOARD_JAPAN106
)
81 scanCode
= DIK_CIRCUMFLEX
;
87 scanCode
= DIK_LBRACKET
;
92 case 0x29: /* Hankaku/Zenkaku */
96 scanCode
= DIK_RBRACKET
;
99 scanCode
= DIK_BACKSLASH
;
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
;
113 if (wparam
!= WM_KEYDOWN
&& wparam
!= WM_KEYUP
&&
114 wparam
!= WM_SYSKEYDOWN
&& wparam
!= WM_SYSKEYUP
)
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;
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
])
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
);
148 const GUID DInput_Wine_Keyboard_GUID
= { /* 0ab8648a-7735-11d2-8c73-71df54a96441 */
149 0x0ab8648a, 0x7735, 0x11d2, {0x8c, 0x73, 0x71, 0xdf, 0x54, 0xa9, 0x64, 0x41}
152 static DWORD
get_keyboard_subtype(void)
154 DWORD kbd_type
, kbd_subtype
, dev_subtype
;
155 kbd_type
= GetKeyboardType(0);
156 kbd_subtype
= GetKeyboardType(1);
158 if (kbd_type
== 4 || (kbd_type
== 7 && kbd_subtype
== 0))
159 dev_subtype
= DIDEVTYPEKEYBOARD_PCENH
;
160 else if (kbd_type
== 7 && kbd_subtype
== 2)
161 dev_subtype
= DIDEVTYPEKEYBOARD_JAPAN106
;
163 FIXME("Unknown keyboard type=%u, subtype=%u\n", kbd_type
, kbd_subtype
);
164 dev_subtype
= DIDEVTYPEKEYBOARD_PCENH
;
169 static void fill_keyboard_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, DWORD subtype
) {
171 DIDEVICEINSTANCEA ddi
;
173 dwSize
= lpddi
->dwSize
;
175 TRACE("%d %p\n", dwSize
, lpddi
);
177 memset(lpddi
, 0, dwSize
);
178 memset(&ddi
, 0, sizeof(ddi
));
181 ddi
.guidInstance
= GUID_SysKeyboard
;/* DInput's GUID */
182 ddi
.guidProduct
= DInput_Wine_Keyboard_GUID
; /* Vendor's GUID */
183 if (version
>= 0x0800)
184 ddi
.dwDevType
= DI8DEVTYPE_KEYBOARD
| (subtype
<< 8);
186 ddi
.dwDevType
= DIDEVTYPE_KEYBOARD
| (subtype
<< 8);
187 strcpy(ddi
.tszInstanceName
, "Keyboard");
188 strcpy(ddi
.tszProductName
, "Wine Keyboard");
190 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
193 static void fill_keyboard_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, DWORD subtype
) {
195 DIDEVICEINSTANCEW ddi
;
197 dwSize
= lpddi
->dwSize
;
199 TRACE("%d %p\n", dwSize
, lpddi
);
201 memset(lpddi
, 0, dwSize
);
202 memset(&ddi
, 0, sizeof(ddi
));
205 ddi
.guidInstance
= GUID_SysKeyboard
;/* DInput's GUID */
206 ddi
.guidProduct
= DInput_Wine_Keyboard_GUID
; /* Vendor's GUID */
207 if (version
>= 0x0800)
208 ddi
.dwDevType
= DI8DEVTYPE_KEYBOARD
| (subtype
<< 8);
210 ddi
.dwDevType
= DIDEVTYPE_KEYBOARD
| (subtype
<< 8);
211 MultiByteToWideChar(CP_ACP
, 0, "Keyboard", -1, ddi
.tszInstanceName
, MAX_PATH
);
212 MultiByteToWideChar(CP_ACP
, 0, "Wine Keyboard", -1, ddi
.tszProductName
, MAX_PATH
);
214 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
217 static HRESULT
keyboarddev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
222 if ((dwDevType
== 0) ||
223 ((dwDevType
== DIDEVTYPE_KEYBOARD
) && (version
< 0x0800)) ||
224 (((dwDevType
== DI8DEVCLASS_KEYBOARD
) || (dwDevType
== DI8DEVTYPE_KEYBOARD
)) && (version
>= 0x0800))) {
225 TRACE("Enumerating the Keyboard device\n");
227 fill_keyboard_dideviceinstanceA(lpddi
, version
, get_keyboard_subtype());
235 static HRESULT
keyboarddev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
240 if ((dwDevType
== 0) ||
241 ((dwDevType
== DIDEVTYPE_KEYBOARD
) && (version
< 0x0800)) ||
242 (((dwDevType
== DI8DEVCLASS_KEYBOARD
) || (dwDevType
== DI8DEVTYPE_KEYBOARD
)) && (version
>= 0x0800))) {
243 TRACE("Enumerating the Keyboard device\n");
245 fill_keyboard_dideviceinstanceW(lpddi
, version
, get_keyboard_subtype());
253 static SysKeyboardImpl
*alloc_device(REFGUID rguid
, IDirectInputImpl
*dinput
)
255 SysKeyboardImpl
* newDevice
;
256 LPDIDATAFORMAT df
= NULL
;
259 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(SysKeyboardImpl
));
260 newDevice
->base
.IDirectInputDevice8A_iface
.lpVtbl
= &SysKeyboardAvt
;
261 newDevice
->base
.IDirectInputDevice8W_iface
.lpVtbl
= &SysKeyboardWvt
;
262 newDevice
->base
.ref
= 1;
263 memcpy(&newDevice
->base
.guid
, rguid
, sizeof(*rguid
));
264 newDevice
->base
.dinput
= dinput
;
265 newDevice
->base
.event_proc
= KeyboardCallback
;
266 InitializeCriticalSection(&newDevice
->base
.crit
);
267 newDevice
->base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": SysKeyboardImpl*->base.crit");
268 newDevice
->subtype
= get_keyboard_subtype();
270 /* Create copy of default data format */
271 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIKeyboard
.dwSize
))) goto failed
;
272 memcpy(df
, &c_dfDIKeyboard
, c_dfDIKeyboard
.dwSize
);
273 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
275 for (i
= 0; i
< df
->dwNumObjs
; i
++)
280 if (!GetKeyNameTextA(((i
& 0x7f) << 16) | ((i
& 0x80) << 17), buf
, sizeof(buf
)))
283 dik_code
= map_dik_code(i
, 0, newDevice
->subtype
);
284 memcpy(&df
->rgodf
[idx
], &c_dfDIKeyboard
.rgodf
[dik_code
], df
->dwObjSize
);
285 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(dik_code
) | DIDFT_PSHBUTTON
;
289 newDevice
->base
.data_format
.wine_df
= df
;
290 IDirectInput_AddRef(&newDevice
->base
.dinput
->IDirectInput7A_iface
);
292 EnterCriticalSection(&dinput
->crit
);
293 list_add_tail(&dinput
->devices_list
, &newDevice
->base
.entry
);
294 LeaveCriticalSection(&dinput
->crit
);
299 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
300 HeapFree(GetProcessHeap(), 0, df
);
301 HeapFree(GetProcessHeap(), 0, newDevice
);
306 static HRESULT
keyboarddev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
308 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
311 if (IsEqualGUID(&GUID_SysKeyboard
, rguid
) || /* Generic Keyboard */
312 IsEqualGUID(&DInput_Wine_Keyboard_GUID
, rguid
)) /* Wine Keyboard */
314 SysKeyboardImpl
*This
;
318 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
319 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
320 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
321 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
325 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
326 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
327 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
328 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
334 WARN("no interface\n");
335 return DIERR_NOINTERFACE
;
338 This
= alloc_device(rguid
, dinput
);
339 TRACE("Created a Keyboard device (%p)\n", This
);
341 if (!This
) return DIERR_OUTOFMEMORY
;
344 *pdev
= &This
->base
.IDirectInputDevice8W_iface
;
346 *pdev
= &This
->base
.IDirectInputDevice8A_iface
;
351 return DIERR_DEVICENOTREG
;
354 const struct dinput_device keyboard_device
= {
355 "Wine keyboard driver",
356 keyboarddev_enum_deviceA
,
357 keyboarddev_enum_deviceW
,
358 keyboarddev_create_device
361 static HRESULT WINAPI
SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface
, DWORD len
, LPVOID ptr
)
363 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
364 TRACE("(%p)->(%d,%p)\n", This
, len
, ptr
);
366 if (!This
->base
.acquired
) return DIERR_NOTACQUIRED
;
368 if (len
!= This
->base
.data_format
.user_df
->dwDataSize
)
369 return DIERR_INVALIDPARAM
;
371 check_dinput_events();
373 EnterCriticalSection(&This
->base
.crit
);
375 if (TRACE_ON(dinput
)) {
377 for (i
= 0; i
< WINE_DINPUT_KEYBOARD_MAX_KEYS
; i
++) {
378 if (This
->DInputKeyState
[i
] != 0x00)
379 TRACE(" - %02X: %02x\n", i
, This
->DInputKeyState
[i
]);
383 fill_DataFormat(ptr
, len
, This
->DInputKeyState
, &This
->base
.data_format
);
384 LeaveCriticalSection(&This
->base
.crit
);
389 static HRESULT WINAPI
SysKeyboardAImpl_GetDeviceState(LPDIRECTINPUTDEVICE8A iface
, DWORD len
, LPVOID ptr
)
391 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
392 return SysKeyboardWImpl_GetDeviceState(IDirectInputDevice8W_from_impl(This
), len
, ptr
);
395 /******************************************************************************
396 * GetCapabilities : get the device capabilities
398 static HRESULT WINAPI
SysKeyboardWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W iface
, LPDIDEVCAPS lpDIDevCaps
)
400 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
403 TRACE("(this=%p,%p)\n",This
,lpDIDevCaps
);
405 if ((lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS
)) && (lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS_DX3
))) {
406 WARN("invalid parameter\n");
407 return DIERR_INVALIDPARAM
;
410 devcaps
.dwSize
= lpDIDevCaps
->dwSize
;
411 devcaps
.dwFlags
= DIDC_ATTACHED
| DIDC_EMULATED
;
412 if (This
->base
.dinput
->dwVersion
>= 0x0800)
413 devcaps
.dwDevType
= DI8DEVTYPE_KEYBOARD
| (This
->subtype
<< 8);
415 devcaps
.dwDevType
= DIDEVTYPE_KEYBOARD
| (This
->subtype
<< 8);
417 devcaps
.dwButtons
= This
->base
.data_format
.wine_df
->dwNumObjs
;
419 devcaps
.dwFFSamplePeriod
= 0;
420 devcaps
.dwFFMinTimeResolution
= 0;
421 devcaps
.dwFirmwareRevision
= 100;
422 devcaps
.dwHardwareRevision
= 100;
423 devcaps
.dwFFDriverVersion
= 0;
425 memcpy(lpDIDevCaps
, &devcaps
, lpDIDevCaps
->dwSize
);
430 static HRESULT WINAPI
SysKeyboardAImpl_GetCapabilities(LPDIRECTINPUTDEVICE8A iface
, LPDIDEVCAPS lpDIDevCaps
)
432 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
433 return SysKeyboardWImpl_GetCapabilities(IDirectInputDevice8W_from_impl(This
), lpDIDevCaps
);
436 /******************************************************************************
437 * GetObjectInfo : get information about a device object such as a button
440 static HRESULT WINAPI
441 SysKeyboardAImpl_GetObjectInfo(
442 LPDIRECTINPUTDEVICE8A iface
,
443 LPDIDEVICEOBJECTINSTANCEA pdidoi
,
450 res
= IDirectInputDevice2AImpl_GetObjectInfo(iface
, pdidoi
, dwObj
, dwHow
);
451 if (res
!= DI_OK
) return res
;
453 scan
= DIDFT_GETINSTANCE(pdidoi
->dwType
);
454 if (scan
== DIK_PAUSE
|| scan
== DIK_NUMLOCK
) scan
^= 0x80;
455 if (!GetKeyNameTextA((scan
& 0x80) << 17 | (scan
& 0x7f) << 16,
456 pdidoi
->tszName
, sizeof(pdidoi
->tszName
)))
457 return DIERR_OBJECTNOTFOUND
;
459 _dump_OBJECTINSTANCEA(pdidoi
);
463 static HRESULT WINAPI
SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface
,
464 LPDIDEVICEOBJECTINSTANCEW pdidoi
,
471 res
= IDirectInputDevice2WImpl_GetObjectInfo(iface
, pdidoi
, dwObj
, dwHow
);
472 if (res
!= DI_OK
) return res
;
474 scan
= DIDFT_GETINSTANCE(pdidoi
->dwType
);
475 if (scan
== DIK_PAUSE
|| scan
== DIK_NUMLOCK
) scan
^= 0x80;
476 if (!GetKeyNameTextW((scan
& 0x80) << 17 | (scan
& 0x7f) << 16,
477 pdidoi
->tszName
, sizeof(pdidoi
->tszName
)/sizeof(pdidoi
->tszName
[0])))
478 return DIERR_OBJECTNOTFOUND
;
480 _dump_OBJECTINSTANCEW(pdidoi
);
484 /******************************************************************************
485 * GetDeviceInfo : get information about a device's identity
487 static HRESULT WINAPI
SysKeyboardAImpl_GetDeviceInfo(
488 LPDIRECTINPUTDEVICE8A iface
,
489 LPDIDEVICEINSTANCEA pdidi
)
491 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
492 TRACE("(this=%p,%p)\n", This
, pdidi
);
494 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)) {
495 WARN(" dinput3 not supported yet...\n");
499 fill_keyboard_dideviceinstanceA(pdidi
, This
->base
.dinput
->dwVersion
, This
->subtype
);
504 static HRESULT WINAPI
SysKeyboardWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
, LPDIDEVICEINSTANCEW pdidi
)
506 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
507 TRACE("(this=%p,%p)\n", This
, pdidi
);
509 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)) {
510 WARN(" dinput3 not supported yet...\n");
514 fill_keyboard_dideviceinstanceW(pdidi
, This
->base
.dinput
->dwVersion
, This
->subtype
);
519 /******************************************************************************
520 * GetProperty : Retrieves information about the input device.
522 static HRESULT WINAPI
SysKeyboardWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
,
523 REFGUID rguid
, LPDIPROPHEADER pdiph
)
525 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
527 TRACE("(%p) %s,%p\n", iface
, debugstr_guid(rguid
), pdiph
);
528 _dump_DIPROPHEADER(pdiph
);
530 if (!IS_DIPROP(rguid
)) return DI_OK
;
532 switch (LOWORD(rguid
))
534 case (DWORD_PTR
)DIPROP_KEYNAME
:
537 LPDIPROPSTRING ps
= (LPDIPROPSTRING
)pdiph
;
538 DIDEVICEOBJECTINSTANCEW didoi
;
540 if (pdiph
->dwSize
!= sizeof(DIPROPSTRING
))
541 return DIERR_INVALIDPARAM
;
543 didoi
.dwSize
= sizeof(DIDEVICEOBJECTINSTANCEW
);
545 hr
= SysKeyboardWImpl_GetObjectInfo(iface
, &didoi
, ps
->diph
.dwObj
, ps
->diph
.dwHow
);
547 memcpy(ps
->wsz
, didoi
.tszName
, sizeof(ps
->wsz
));
550 case (DWORD_PTR
) DIPROP_RANGE
:
551 return DIERR_UNSUPPORTED
;
553 return IDirectInputDevice2AImpl_GetProperty( IDirectInputDevice8A_from_impl(This
), rguid
, pdiph
);
558 static HRESULT WINAPI
SysKeyboardAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
559 REFGUID rguid
, LPDIPROPHEADER pdiph
)
561 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
562 return SysKeyboardWImpl_GetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, pdiph
);
565 static HRESULT WINAPI
SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface
)
567 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
570 TRACE("(%p)\n", This
);
572 res
= IDirectInputDevice2WImpl_Acquire(iface
);
575 TRACE("clearing keystate\n");
576 memset(This
->DInputKeyState
, 0, sizeof(This
->DInputKeyState
));
582 static HRESULT WINAPI
SysKeyboardAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
584 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
585 return SysKeyboardWImpl_Acquire(IDirectInputDevice8W_from_impl(This
));
588 static HRESULT WINAPI
SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface
,
589 LPDIACTIONFORMATW lpdiaf
,
590 LPCWSTR lpszUserName
,
593 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface
, lpdiaf
, debugstr_w(lpszUserName
), dwFlags
);
595 return _build_action_map(iface
, lpdiaf
, lpszUserName
, dwFlags
, DIKEYBOARD_MASK
, &c_dfDIKeyboard
);
598 static HRESULT WINAPI
SysKeyboardAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface
,
599 LPDIACTIONFORMATA lpdiaf
,
603 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
604 DIACTIONFORMATW diafW
;
606 WCHAR
*lpszUserNameW
= NULL
;
609 diafW
.rgoAction
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW
)*lpdiaf
->dwNumActions
);
610 _copy_diactionformatAtoW(&diafW
, lpdiaf
);
612 if (lpszUserName
!= NULL
)
614 username_size
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
615 lpszUserNameW
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*username_size
);
616 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, lpszUserNameW
, username_size
);
619 hr
= SysKeyboardWImpl_BuildActionMap(&This
->base
.IDirectInputDevice8W_iface
, &diafW
, lpszUserNameW
, dwFlags
);
621 _copy_diactionformatWtoA(lpdiaf
, &diafW
);
622 HeapFree(GetProcessHeap(), 0, diafW
.rgoAction
);
623 HeapFree(GetProcessHeap(), 0, lpszUserNameW
);
628 static HRESULT WINAPI
SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface
,
629 LPDIACTIONFORMATW lpdiaf
,
630 LPCWSTR lpszUserName
,
633 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface
, lpdiaf
, debugstr_w(lpszUserName
), dwFlags
);
635 return _set_action_map(iface
, lpdiaf
, lpszUserName
, dwFlags
, &c_dfDIKeyboard
);
638 static HRESULT WINAPI
SysKeyboardAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface
,
639 LPDIACTIONFORMATA lpdiaf
,
643 SysKeyboardImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
644 DIACTIONFORMATW diafW
;
646 WCHAR
*lpszUserNameW
= NULL
;
649 diafW
.rgoAction
= HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW
)*lpdiaf
->dwNumActions
);
650 _copy_diactionformatAtoW(&diafW
, lpdiaf
);
652 if (lpszUserName
!= NULL
)
654 username_size
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
655 lpszUserNameW
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*username_size
);
656 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, lpszUserNameW
, username_size
);
659 hr
= SysKeyboardWImpl_SetActionMap(&This
->base
.IDirectInputDevice8W_iface
, &diafW
, lpszUserNameW
, dwFlags
);
661 HeapFree(GetProcessHeap(), 0, diafW
.rgoAction
);
662 HeapFree(GetProcessHeap(), 0, lpszUserNameW
);
667 static const IDirectInputDevice8AVtbl SysKeyboardAvt
=
669 IDirectInputDevice2AImpl_QueryInterface
,
670 IDirectInputDevice2AImpl_AddRef
,
671 IDirectInputDevice2AImpl_Release
,
672 SysKeyboardAImpl_GetCapabilities
,
673 IDirectInputDevice2AImpl_EnumObjects
,
674 SysKeyboardAImpl_GetProperty
,
675 IDirectInputDevice2AImpl_SetProperty
,
676 SysKeyboardAImpl_Acquire
,
677 IDirectInputDevice2AImpl_Unacquire
,
678 SysKeyboardAImpl_GetDeviceState
,
679 IDirectInputDevice2AImpl_GetDeviceData
,
680 IDirectInputDevice2AImpl_SetDataFormat
,
681 IDirectInputDevice2AImpl_SetEventNotification
,
682 IDirectInputDevice2AImpl_SetCooperativeLevel
,
683 SysKeyboardAImpl_GetObjectInfo
,
684 SysKeyboardAImpl_GetDeviceInfo
,
685 IDirectInputDevice2AImpl_RunControlPanel
,
686 IDirectInputDevice2AImpl_Initialize
,
687 IDirectInputDevice2AImpl_CreateEffect
,
688 IDirectInputDevice2AImpl_EnumEffects
,
689 IDirectInputDevice2AImpl_GetEffectInfo
,
690 IDirectInputDevice2AImpl_GetForceFeedbackState
,
691 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
692 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
693 IDirectInputDevice2AImpl_Escape
,
694 IDirectInputDevice2AImpl_Poll
,
695 IDirectInputDevice2AImpl_SendDeviceData
,
696 IDirectInputDevice7AImpl_EnumEffectsInFile
,
697 IDirectInputDevice7AImpl_WriteEffectToFile
,
698 SysKeyboardAImpl_BuildActionMap
,
699 SysKeyboardAImpl_SetActionMap
,
700 IDirectInputDevice8AImpl_GetImageInfo
703 static const IDirectInputDevice8WVtbl SysKeyboardWvt
=
705 IDirectInputDevice2WImpl_QueryInterface
,
706 IDirectInputDevice2WImpl_AddRef
,
707 IDirectInputDevice2WImpl_Release
,
708 SysKeyboardWImpl_GetCapabilities
,
709 IDirectInputDevice2WImpl_EnumObjects
,
710 SysKeyboardWImpl_GetProperty
,
711 IDirectInputDevice2WImpl_SetProperty
,
712 SysKeyboardWImpl_Acquire
,
713 IDirectInputDevice2WImpl_Unacquire
,
714 SysKeyboardWImpl_GetDeviceState
,
715 IDirectInputDevice2WImpl_GetDeviceData
,
716 IDirectInputDevice2WImpl_SetDataFormat
,
717 IDirectInputDevice2WImpl_SetEventNotification
,
718 IDirectInputDevice2WImpl_SetCooperativeLevel
,
719 SysKeyboardWImpl_GetObjectInfo
,
720 SysKeyboardWImpl_GetDeviceInfo
,
721 IDirectInputDevice2WImpl_RunControlPanel
,
722 IDirectInputDevice2WImpl_Initialize
,
723 IDirectInputDevice2WImpl_CreateEffect
,
724 IDirectInputDevice2WImpl_EnumEffects
,
725 IDirectInputDevice2WImpl_GetEffectInfo
,
726 IDirectInputDevice2WImpl_GetForceFeedbackState
,
727 IDirectInputDevice2WImpl_SendForceFeedbackCommand
,
728 IDirectInputDevice2WImpl_EnumCreatedEffectObjects
,
729 IDirectInputDevice2WImpl_Escape
,
730 IDirectInputDevice2WImpl_Poll
,
731 IDirectInputDevice2WImpl_SendDeviceData
,
732 IDirectInputDevice7WImpl_EnumEffectsInFile
,
733 IDirectInputDevice7WImpl_WriteEffectToFile
,
734 SysKeyboardWImpl_BuildActionMap
,
735 SysKeyboardWImpl_SetActionMap
,
736 IDirectInputDevice8WImpl_GetImageInfo