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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 IDirectInputDevice8AVtbl SysKeyboardAvt
;
44 static IDirectInputDevice8WVtbl SysKeyboardWvt
;
46 typedef struct SysKeyboardImpl SysKeyboardImpl
;
47 struct SysKeyboardImpl
53 IDirectInputImpl
* dinput
;
56 /* SysKeyboardAImpl */
58 int buffersize
; /* set in 'SetProperty' */
59 LPDIDEVICEOBJECTDATA buffer
; /* buffer for 'GetDeviceData'.
60 Alloc at 'Acquire', Free at
62 int count
; /* number of objects in use in
64 int start
; /* 'buffer' rotates. This is the
65 first in use (if count > 0) */
66 BOOL overflow
; /* return DI_BUFFEROVERFLOW in
68 CRITICAL_SECTION crit
;
71 static SysKeyboardImpl
* current_lock
= NULL
;
72 /* Today's acquired device
73 * FIXME: currently this can be only one.
74 * Maybe this should be a linked list or st.
75 * I don't know what the rules are for multiple acquired keyboards,
76 * but 'DI_LOSTFOCUS' and 'DI_UNACQUIRED' exist for a reason.
79 static BYTE DInputKeyState
[WINE_DINPUT_KEYBOARD_MAX_KEYS
]; /* array for 'GetDeviceState' */
81 static CRITICAL_SECTION keyboard_crit
;
82 static CRITICAL_SECTION_DEBUG critsect_debug
=
85 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
86 0, 0, { 0, (DWORD
)(__FILE__
": keyboard_crit") }
88 static CRITICAL_SECTION keyboard_crit
= { &critsect_debug
, -1, 0, 0, 0, 0 };
90 static DWORD keyboard_users
= 0;
91 static HHOOK keyboard_hook
= NULL
;
93 LRESULT CALLBACK
KeyboardCallback( int code
, WPARAM wparam
, LPARAM lparam
)
98 KBDLLHOOKSTRUCT
*hook
= (KBDLLHOOKSTRUCT
*)lparam
;
101 TRACE("(%d,%d,%ld)\n", code
, wparam
, lparam
);
103 /** returns now if not HC_ACTION */
104 if (code
!= HC_ACTION
) return CallNextHookEx(keyboard_hook
, code
, wparam
, lparam
);
107 dik_code
= hook
->scanCode
;
108 if (hook
->flags
& LLKHF_EXTENDED
) dik_code
|= 0x80;
109 down
= !(hook
->flags
& LLKHF_UP
);
110 timestamp
= hook
->time
;
113 /** returns now if key event already known */
114 new_diks
= (down
? 0x80 : 0);
115 /*if (new_diks != DInputKeyState[dik_code]) return CallNextHookEx(keyboard_hook, code, wparam, lparam); TO BE FIXED */
117 DInputKeyState
[dik_code
] = new_diks
;
118 TRACE(" setting %02X to %02X\n", dik_code
, DInputKeyState
[dik_code
]);
120 if (current_lock
!= NULL
) {
121 if (current_lock
->hEvent
) SetEvent(current_lock
->hEvent
);
123 if (current_lock
->buffer
!= NULL
) {
126 EnterCriticalSection(&(current_lock
->crit
));
128 n
= (current_lock
->start
+ current_lock
->count
) % current_lock
->buffersize
;
130 current_lock
->buffer
[n
].dwOfs
= dik_code
;
131 current_lock
->buffer
[n
].dwData
= down
? 0x80 : 0;
132 current_lock
->buffer
[n
].dwTimeStamp
= timestamp
;
133 current_lock
->buffer
[n
].dwSequence
= current_lock
->dinput
->evsequence
++;
135 TRACE("Adding event at offset %d : %ld - %ld - %ld - %ld\n", n
,
136 current_lock
->buffer
[n
].dwOfs
, current_lock
->buffer
[n
].dwData
, current_lock
->buffer
[n
].dwTimeStamp
, current_lock
->buffer
[n
].dwSequence
);
138 if (current_lock
->count
== current_lock
->buffersize
) {
139 current_lock
->start
= ++current_lock
->start
% current_lock
->buffersize
;
140 current_lock
->overflow
= TRUE
;
142 current_lock
->count
++;
144 LeaveCriticalSection(&(current_lock
->crit
));
147 return CallNextHookEx(keyboard_hook
, code
, wparam
, lparam
);
150 static GUID DInput_Wine_Keyboard_GUID
= { /* 0ab8648a-7735-11d2-8c73-71df54a96441 */
154 {0x8c, 0x73, 0x71, 0xdf, 0x54, 0xa9, 0x64, 0x41}
157 static void fill_keyboard_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, int version
) {
159 DIDEVICEINSTANCEA ddi
;
161 dwSize
= lpddi
->dwSize
;
163 TRACE("%ld %p\n", dwSize
, lpddi
);
165 memset(lpddi
, 0, dwSize
);
166 memset(&ddi
, 0, sizeof(ddi
));
169 ddi
.guidInstance
= GUID_SysKeyboard
;/* DInput's GUID */
170 ddi
.guidProduct
= DInput_Wine_Keyboard_GUID
; /* Vendor's GUID */
172 ddi
.dwDevType
= DI8DEVTYPE_KEYBOARD
| (DI8DEVTYPEKEYBOARD_UNKNOWN
<< 8);
174 ddi
.dwDevType
= DIDEVTYPE_KEYBOARD
| (DIDEVTYPEKEYBOARD_UNKNOWN
<< 8);
175 strcpy(ddi
.tszInstanceName
, "Keyboard");
176 strcpy(ddi
.tszProductName
, "Wine Keyboard");
178 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
181 static void fill_keyboard_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, int version
) {
183 DIDEVICEINSTANCEW ddi
;
185 dwSize
= lpddi
->dwSize
;
187 TRACE("%ld %p\n", dwSize
, lpddi
);
189 memset(lpddi
, 0, dwSize
);
190 memset(&ddi
, 0, sizeof(ddi
));
193 ddi
.guidInstance
= GUID_SysKeyboard
;/* DInput's GUID */
194 ddi
.guidProduct
= DInput_Wine_Keyboard_GUID
; /* Vendor's GUID */
196 ddi
.dwDevType
= DI8DEVTYPE_KEYBOARD
| (DI8DEVTYPEKEYBOARD_UNKNOWN
<< 8);
198 ddi
.dwDevType
= DIDEVTYPE_KEYBOARD
| (DIDEVTYPEKEYBOARD_UNKNOWN
<< 8);
199 MultiByteToWideChar(CP_ACP
, 0, "Keyboard", -1, ddi
.tszInstanceName
, MAX_PATH
);
200 MultiByteToWideChar(CP_ACP
, 0, "Wine Keyboard", -1, ddi
.tszProductName
, MAX_PATH
);
202 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
205 static BOOL
keyboarddev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, int version
, int id
)
210 if ((dwDevType
== 0) ||
211 ((dwDevType
== DIDEVTYPE_KEYBOARD
) && (version
< 8)) ||
212 (((dwDevType
== DI8DEVCLASS_KEYBOARD
) || (dwDevType
== DI8DEVTYPE_KEYBOARD
)) && (version
>= 8))) {
213 TRACE("Enumerating the Keyboard device\n");
215 fill_keyboard_dideviceinstanceA(lpddi
, version
);
223 static BOOL
keyboarddev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, int version
, int id
)
228 if ((dwDevType
== 0) ||
229 ((dwDevType
== DIDEVTYPE_KEYBOARD
) && (version
< 8)) ||
230 (((dwDevType
== DI8DEVCLASS_KEYBOARD
) || (dwDevType
== DI8DEVTYPE_KEYBOARD
)) && (version
>= 8))) {
231 TRACE("Enumerating the Keyboard device\n");
233 fill_keyboard_dideviceinstanceW(lpddi
, version
);
241 static SysKeyboardImpl
*alloc_device(REFGUID rguid
, LPVOID kvt
, IDirectInputImpl
*dinput
)
243 SysKeyboardImpl
* newDevice
;
246 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(SysKeyboardImpl
));
247 newDevice
->lpVtbl
= kvt
;
249 memcpy(&(newDevice
->guid
),rguid
,sizeof(*rguid
));
250 newDevice
->dinput
= dinput
;
251 InitializeCriticalSection(&(newDevice
->crit
));
253 EnterCriticalSection(&keyboard_crit
);
254 kbd_users
= InterlockedIncrement(&keyboard_users
);
255 if (1 == kbd_users
) {
256 keyboard_hook
= SetWindowsHookExW( WH_KEYBOARD_LL
, KeyboardCallback
, DINPUT_instance
, 0 );
258 LeaveCriticalSection(&keyboard_crit
);
264 static HRESULT
keyboarddev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
266 if ((IsEqualGUID(&GUID_SysKeyboard
,rguid
)) || /* Generic Keyboard */
267 (IsEqualGUID(&DInput_Wine_Keyboard_GUID
,rguid
))) { /* Wine Keyboard */
268 if ((riid
== NULL
) ||
269 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
270 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
271 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
272 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
273 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &SysKeyboardAvt
, dinput
);
274 TRACE("Creating a Keyboard device (%p)\n", *pdev
);
277 return DIERR_NOINTERFACE
;
279 return DIERR_DEVICENOTREG
;
282 static HRESULT
keyboarddev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
284 if ((IsEqualGUID(&GUID_SysKeyboard
,rguid
)) || /* Generic Keyboard */
285 (IsEqualGUID(&DInput_Wine_Keyboard_GUID
,rguid
))) { /* Wine Keyboard */
286 if ((riid
== NULL
) ||
287 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
288 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
289 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
290 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
291 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &SysKeyboardWvt
, dinput
);
292 TRACE("Creating a Keyboard device (%p)\n", *pdev
);
295 return DIERR_NOINTERFACE
;
297 return DIERR_DEVICENOTREG
;
300 const struct dinput_device keyboard_device
= {
301 "Wine keyboard driver",
302 keyboarddev_enum_deviceA
,
303 keyboarddev_enum_deviceW
,
304 keyboarddev_create_deviceA
,
305 keyboarddev_create_deviceW
308 static ULONG WINAPI
SysKeyboardAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
310 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
314 ref
= InterlockedDecrement(&(This
->ref
));
318 EnterCriticalSection(&keyboard_crit
);
319 kbd_users
= InterlockedDecrement(&keyboard_users
);
320 if (0 == kbd_users
) {
321 UnhookWindowsHookEx( keyboard_hook
);
324 LeaveCriticalSection(&keyboard_crit
);
326 /* Free the data queue */
327 HeapFree(GetProcessHeap(),0,This
->buffer
);
329 DeleteCriticalSection(&(This
->crit
));
331 HeapFree(GetProcessHeap(),0,This
);
335 static HRESULT WINAPI
SysKeyboardAImpl_SetProperty(
336 LPDIRECTINPUTDEVICE8A iface
,REFGUID rguid
,LPCDIPROPHEADER ph
339 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
341 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
342 TRACE("(size=%ld,headersize=%ld,obj=%ld,how=%ld\n",
343 ph
->dwSize
,ph
->dwHeaderSize
,ph
->dwObj
,ph
->dwHow
);
344 if (!HIWORD(rguid
)) {
345 switch ((DWORD
)rguid
) {
346 case (DWORD
) DIPROP_BUFFERSIZE
: {
347 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
349 TRACE("(buffersize=%ld)\n",pd
->dwData
);
352 return DIERR_INVALIDPARAM
;
354 This
->buffersize
= pd
->dwData
;
359 WARN("Unknown type %ld\n",(DWORD
)rguid
);
366 static HRESULT WINAPI
SysKeyboardAImpl_GetProperty(
367 LPDIRECTINPUTDEVICE8A iface
,REFGUID rguid
,LPDIPROPHEADER ph
370 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
372 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
373 TRACE("(size=%ld,headersize=%ld,obj=%ld,how=%ld\n",
374 ph
->dwSize
,ph
->dwHeaderSize
,ph
->dwObj
,ph
->dwHow
);
375 if (!HIWORD(rguid
)) {
376 switch ((DWORD
)rguid
) {
377 case (DWORD
) DIPROP_BUFFERSIZE
: {
378 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)ph
;
380 TRACE("(buffersize=%ld)\n",pd
->dwData
);
383 return DIERR_INVALIDPARAM
;
385 pd
->dwData
= This
->buffersize
;
390 WARN("Unknown type %ld\n",(DWORD
)rguid
);
397 static HRESULT WINAPI
SysKeyboardAImpl_GetDeviceState(
398 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
401 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
402 TRACE("(%p)->(%ld,%p)\n", This
, len
, ptr
);
404 /* Note: device does not need to be acquired */
405 if (len
!= WINE_DINPUT_KEYBOARD_MAX_KEYS
)
406 return DIERR_INVALIDPARAM
;
408 MsgWaitForMultipleObjectsEx(0, NULL
, 0, QS_ALLINPUT
, 0);
410 EnterCriticalSection(&(This
->crit
));
412 if (TRACE_ON(dinput
)) {
414 for (i
= 0; i
< WINE_DINPUT_KEYBOARD_MAX_KEYS
; i
++) {
415 if (DInputKeyState
[i
] != 0x00) {
416 TRACE(" - %02X: %02x\n", i
, DInputKeyState
[i
]);
421 memcpy(ptr
, DInputKeyState
, WINE_DINPUT_KEYBOARD_MAX_KEYS
);
422 LeaveCriticalSection(&(This
->crit
));
427 static HRESULT WINAPI
SysKeyboardAImpl_GetDeviceData(
428 LPDIRECTINPUTDEVICE8A iface
,DWORD dodsize
,LPDIDEVICEOBJECTDATA dod
,
429 LPDWORD entries
,DWORD flags
432 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
433 int ret
= DI_OK
, i
= 0;
435 TRACE("(this=%p,%ld,%p,%p(%ld)),0x%08lx)\n",
436 This
,dodsize
,dod
,entries
,entries
?*entries
:0,flags
);
438 if (This
->acquired
== 0)
439 return DIERR_NOTACQUIRED
;
441 if (This
->buffer
== NULL
)
442 return DIERR_NOTBUFFERED
;
444 if (dodsize
< sizeof(DIDEVICEOBJECTDATA_DX3
))
445 return DIERR_INVALIDPARAM
;
447 MsgWaitForMultipleObjectsEx(0, NULL
, 0, QS_ALLINPUT
, 0);
449 EnterCriticalSection(&(This
->crit
));
451 /* Copy item at a time for the case dodsize > sizeof(buffer[n]) */
452 while ((i
< *entries
|| *entries
== INFINITE
) && i
< This
->count
)
456 int n
= (This
->start
+ i
) % This
->buffersize
;
457 LPDIDEVICEOBJECTDATA pd
458 = (LPDIDEVICEOBJECTDATA
)((BYTE
*)dod
+ dodsize
* i
);
459 pd
->dwOfs
= This
->buffer
[n
].dwOfs
;
460 pd
->dwData
= This
->buffer
[n
].dwData
;
461 pd
->dwTimeStamp
= This
->buffer
[n
].dwTimeStamp
;
462 pd
->dwSequence
= This
->buffer
[n
].dwSequence
;
470 ret
= DI_BUFFEROVERFLOW
;
472 if (!(flags
& DIGDD_PEEK
))
476 This
->start
= (This
->start
+ i
) % This
->buffersize
;
477 This
->overflow
= FALSE
;
480 LeaveCriticalSection(&(This
->crit
));
482 TRACE("Returning %ld events queued\n", *entries
);
487 static HRESULT WINAPI
SysKeyboardAImpl_EnumObjects(
488 LPDIRECTINPUTDEVICE8A iface
,
489 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
493 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
494 DIDEVICEOBJECTINSTANCEA ddoi
;
497 TRACE("(this=%p,%p,%p,%08lx)\n", This
, lpCallback
, lpvRef
, dwFlags
);
498 if (TRACE_ON(dinput
)) {
499 TRACE(" - flags = ");
500 _dump_EnumObjects_flags(dwFlags
);
504 /* Only the fields till dwFFMaxForce are relevant */
505 memset(&ddoi
, 0, sizeof(ddoi
));
506 ddoi
.dwSize
= FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA
, dwFFMaxForce
);
508 for (i
= 0; i
< WINE_DINPUT_KEYBOARD_MAX_KEYS
; i
++) {
509 /* Report 255 keys :-) */
510 ddoi
.guidType
= GUID_Key
;
512 ddoi
.dwType
= DIDFT_MAKEINSTANCE(i
) | DIDFT_BUTTON
;
513 GetKeyNameTextA(((i
& 0x7f) << 16) | ((i
& 0x80) << 17), ddoi
.tszName
, sizeof(ddoi
.tszName
));
514 _dump_OBJECTINSTANCEA(&ddoi
);
515 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) return DI_OK
;
521 static HRESULT WINAPI
SysKeyboardWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface
,
522 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback
,
526 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
528 device_enumobjects_AtoWcb_data data
;
530 data
.lpCallBack
= lpCallback
;
531 data
.lpvRef
= lpvRef
;
533 return SysKeyboardAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A
) This
, (LPDIENUMDEVICEOBJECTSCALLBACKA
) DIEnumDevicesCallbackAtoW
, (LPVOID
) &data
, dwFlags
);
536 static HRESULT WINAPI
SysKeyboardAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
);
538 static HRESULT WINAPI
SysKeyboardAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
540 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
542 TRACE("(this=%p)\n",This
);
549 if (current_lock
!= NULL
) {
550 FIXME("Not more than one keyboard can be acquired at the same time.\n");
551 SysKeyboardAImpl_Unacquire(iface
);
556 if (This
->buffersize
> 0) {
557 This
->buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
558 This
->buffersize
* sizeof(*(This
->buffer
)));
561 This
->overflow
= FALSE
;
566 /*keyboard_hook = SetWindowsHookExW( WH_KEYBOARD_LL, KeyboardCallback, DINPUT_instance, 0 );*/
571 static HRESULT WINAPI
SysKeyboardAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
573 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
574 TRACE("(this=%p)\n",This
);
576 if (This
->acquired
== 0)
580 if (current_lock
== This
)
583 ERR("this != current_lock\n");
585 /* Unacquire device */
588 if (This
->buffersize
>= 0) {
589 HeapFree(GetProcessHeap(), 0, This
->buffer
);
596 static HRESULT WINAPI
SysKeyboardAImpl_SetEventNotification(LPDIRECTINPUTDEVICE8A iface
,
598 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
600 TRACE("(this=%p,0x%08lx)\n",This
,(DWORD
)hnd
);
606 /******************************************************************************
607 * GetCapabilities : get the device capablitites
609 static HRESULT WINAPI
SysKeyboardAImpl_GetCapabilities(
610 LPDIRECTINPUTDEVICE8A iface
,
611 LPDIDEVCAPS lpDIDevCaps
)
613 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
616 TRACE("(this=%p,%p)\n",This
,lpDIDevCaps
);
618 if ((lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS
)) && (lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS_DX3
))) {
619 WARN("invalid parameter\n");
620 return DIERR_INVALIDPARAM
;
623 devcaps
.dwSize
= lpDIDevCaps
->dwSize
;
624 devcaps
.dwFlags
= DIDC_ATTACHED
;
625 if (This
->dinput
->version
>= 8)
626 devcaps
.dwDevType
= DI8DEVTYPE_KEYBOARD
| (DI8DEVTYPEKEYBOARD_UNKNOWN
<< 8);
628 devcaps
.dwDevType
= DIDEVTYPE_KEYBOARD
| (DIDEVTYPEKEYBOARD_UNKNOWN
<< 8);
630 devcaps
.dwButtons
= WINE_DINPUT_KEYBOARD_MAX_KEYS
;
632 devcaps
.dwFFSamplePeriod
= 0;
633 devcaps
.dwFFMinTimeResolution
= 0;
634 devcaps
.dwFirmwareRevision
= 100;
635 devcaps
.dwHardwareRevision
= 100;
636 devcaps
.dwFFDriverVersion
= 0;
638 memcpy(lpDIDevCaps
, &devcaps
, lpDIDevCaps
->dwSize
);
643 /******************************************************************************
644 * GetObjectInfo : get information about a device object such as a button
647 static HRESULT WINAPI
648 SysKeyboardAImpl_GetObjectInfo(
649 LPDIRECTINPUTDEVICE8A iface
,
650 LPDIDEVICEOBJECTINSTANCEA pdidoi
,
654 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
655 DIDEVICEOBJECTINSTANCEA ddoi
;
656 DWORD dwSize
= pdidoi
->dwSize
;
658 TRACE("(this=%p,%p,%ld,0x%08lx)\n", This
, pdidoi
, dwObj
, dwHow
);
660 if (dwHow
== DIPH_BYID
) {
661 WARN(" querying by id not supported yet...\n");
665 memset(pdidoi
, 0, dwSize
);
666 memset(&ddoi
, 0, sizeof(ddoi
));
668 ddoi
.dwSize
= dwSize
;
669 ddoi
.guidType
= GUID_Key
;
671 ddoi
.dwType
= DIDFT_MAKEINSTANCE(dwObj
) | DIDFT_BUTTON
;
672 GetKeyNameTextA(((dwObj
& 0x7f) << 16) | ((dwObj
& 0x80) << 17), ddoi
.tszName
, sizeof(ddoi
.tszName
));
674 /* And return our just filled device object instance structure */
675 memcpy(pdidoi
, &ddoi
, (dwSize
< sizeof(ddoi
) ? dwSize
: sizeof(ddoi
)));
677 _dump_OBJECTINSTANCEA(pdidoi
);
682 static HRESULT WINAPI
SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface
,
683 LPDIDEVICEOBJECTINSTANCEW pdidoi
,
687 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
688 DIDEVICEOBJECTINSTANCEW ddoi
;
689 DWORD dwSize
= pdidoi
->dwSize
;
691 TRACE("(this=%p,%p,%ld,0x%08lx)\n", This
, pdidoi
, dwObj
, dwHow
);
693 if (dwHow
== DIPH_BYID
) {
694 WARN(" querying by id not supported yet...\n");
698 memset(pdidoi
, 0, dwSize
);
699 memset(&ddoi
, 0, sizeof(ddoi
));
701 ddoi
.dwSize
= dwSize
;
702 ddoi
.guidType
= GUID_Key
;
704 ddoi
.dwType
= DIDFT_MAKEINSTANCE(dwObj
) | DIDFT_BUTTON
;
705 GetKeyNameTextW(((dwObj
& 0x7f) << 16) | ((dwObj
& 0x80) << 17), ddoi
.tszName
, sizeof(ddoi
.tszName
));
707 /* And return our just filled device object instance structure */
708 memcpy(pdidoi
, &ddoi
, (dwSize
< sizeof(ddoi
) ? dwSize
: sizeof(ddoi
)));
710 _dump_OBJECTINSTANCEW(pdidoi
);
715 /******************************************************************************
716 * GetDeviceInfo : get information about a device's identity
718 static HRESULT WINAPI
SysKeyboardAImpl_GetDeviceInfo(
719 LPDIRECTINPUTDEVICE8A iface
,
720 LPDIDEVICEINSTANCEA pdidi
)
722 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
723 TRACE("(this=%p,%p)\n", This
, pdidi
);
725 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)) {
726 WARN(" dinput3 not supported yet...\n");
730 fill_keyboard_dideviceinstanceA(pdidi
, This
->dinput
->version
);
735 static HRESULT WINAPI
SysKeyboardWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
, LPDIDEVICEINSTANCEW pdidi
)
737 SysKeyboardImpl
*This
= (SysKeyboardImpl
*)iface
;
738 TRACE("(this=%p,%p)\n", This
, pdidi
);
740 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)) {
741 WARN(" dinput3 not supported yet...\n");
745 fill_keyboard_dideviceinstanceW(pdidi
, This
->dinput
->version
);
750 static IDirectInputDevice8AVtbl SysKeyboardAvt
=
752 IDirectInputDevice2AImpl_QueryInterface
,
753 IDirectInputDevice2AImpl_AddRef
,
754 SysKeyboardAImpl_Release
,
755 SysKeyboardAImpl_GetCapabilities
,
756 SysKeyboardAImpl_EnumObjects
,
757 SysKeyboardAImpl_GetProperty
,
758 SysKeyboardAImpl_SetProperty
,
759 SysKeyboardAImpl_Acquire
,
760 SysKeyboardAImpl_Unacquire
,
761 SysKeyboardAImpl_GetDeviceState
,
762 SysKeyboardAImpl_GetDeviceData
,
763 IDirectInputDevice2AImpl_SetDataFormat
,
764 SysKeyboardAImpl_SetEventNotification
,
765 IDirectInputDevice2AImpl_SetCooperativeLevel
,
766 SysKeyboardAImpl_GetObjectInfo
,
767 SysKeyboardAImpl_GetDeviceInfo
,
768 IDirectInputDevice2AImpl_RunControlPanel
,
769 IDirectInputDevice2AImpl_Initialize
,
770 IDirectInputDevice2AImpl_CreateEffect
,
771 IDirectInputDevice2AImpl_EnumEffects
,
772 IDirectInputDevice2AImpl_GetEffectInfo
,
773 IDirectInputDevice2AImpl_GetForceFeedbackState
,
774 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
775 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
776 IDirectInputDevice2AImpl_Escape
,
777 IDirectInputDevice2AImpl_Poll
,
778 IDirectInputDevice2AImpl_SendDeviceData
,
779 IDirectInputDevice7AImpl_EnumEffectsInFile
,
780 IDirectInputDevice7AImpl_WriteEffectToFile
,
781 IDirectInputDevice8AImpl_BuildActionMap
,
782 IDirectInputDevice8AImpl_SetActionMap
,
783 IDirectInputDevice8AImpl_GetImageInfo
786 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
787 # define XCAST(fun) (typeof(SysKeyboardWvt.fun))
789 # define XCAST(fun) (void*)
792 static IDirectInputDevice8WVtbl SysKeyboardWvt
=
794 IDirectInputDevice2WImpl_QueryInterface
,
795 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
796 XCAST(Release
)SysKeyboardAImpl_Release
,
797 XCAST(GetCapabilities
)SysKeyboardAImpl_GetCapabilities
,
798 SysKeyboardWImpl_EnumObjects
,
799 XCAST(GetProperty
)SysKeyboardAImpl_GetProperty
,
800 XCAST(SetProperty
)SysKeyboardAImpl_SetProperty
,
801 XCAST(Acquire
)SysKeyboardAImpl_Acquire
,
802 XCAST(Unacquire
)SysKeyboardAImpl_Unacquire
,
803 XCAST(GetDeviceState
)SysKeyboardAImpl_GetDeviceState
,
804 XCAST(GetDeviceData
)SysKeyboardAImpl_GetDeviceData
,
805 XCAST(SetDataFormat
)IDirectInputDevice2AImpl_SetDataFormat
,
806 XCAST(SetEventNotification
)SysKeyboardAImpl_SetEventNotification
,
807 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
808 SysKeyboardWImpl_GetObjectInfo
,
809 SysKeyboardWImpl_GetDeviceInfo
,
810 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
811 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
812 XCAST(CreateEffect
)IDirectInputDevice2AImpl_CreateEffect
,
813 IDirectInputDevice2WImpl_EnumEffects
,
814 IDirectInputDevice2WImpl_GetEffectInfo
,
815 XCAST(GetForceFeedbackState
)IDirectInputDevice2AImpl_GetForceFeedbackState
,
816 XCAST(SendForceFeedbackCommand
)IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
817 XCAST(EnumCreatedEffectObjects
)IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
818 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
819 XCAST(Poll
)IDirectInputDevice2AImpl_Poll
,
820 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
821 IDirectInputDevice7WImpl_EnumEffectsInFile
,
822 IDirectInputDevice7WImpl_WriteEffectToFile
,
823 IDirectInputDevice8WImpl_BuildActionMap
,
824 IDirectInputDevice8WImpl_SetActionMap
,
825 IDirectInputDevice8WImpl_GetImageInfo