- use WINE_DINPUT_KEYBOARD_MAX_KEYS instead hard-coded 256 value
[wine/multimedia.git] / dlls / dinput / keyboard.c
blob1114d5f87272e7e8098720d09d63d44a30c83be4
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
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 IDirectInputDevice8AVtbl SysKeyboardAvt;
44 static IDirectInputDevice8WVtbl SysKeyboardWvt;
46 typedef struct SysKeyboardImpl SysKeyboardImpl;
47 struct SysKeyboardImpl
49 LPVOID lpVtbl;
50 DWORD ref;
51 GUID guid;
53 IDirectInputImpl* dinput;
55 HANDLE hEvent;
56 /* SysKeyboardAImpl */
57 int acquired;
58 int buffersize; /* set in 'SetProperty' */
59 LPDIDEVICEOBJECTDATA buffer; /* buffer for 'GetDeviceData'.
60 Alloc at 'Acquire', Free at
61 'Unacquire' */
62 int count; /* number of objects in use in
63 'buffer' */
64 int start; /* 'buffer' rotates. This is the
65 first in use (if count > 0) */
66 BOOL overflow; /* return DI_BUFFEROVERFLOW in
67 'GetDeviceData' */
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 =
84 0, 0, &keyboard_crit,
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 )
95 BYTE dik_code;
96 BOOL down;
97 DWORD timestamp;
98 KBDLLHOOKSTRUCT *hook = (KBDLLHOOKSTRUCT *)lparam;
99 BYTE new_diks;
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) {
124 int n;
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;
141 } else
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 */
151 0x0ab8648a,
152 0x7735,
153 0x11d2,
154 {0x8c, 0x73, 0x71, 0xdf, 0x54, 0xa9, 0x64, 0x41}
157 static void fill_keyboard_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, int version) {
158 DWORD dwSize;
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));
168 ddi.dwSize = dwSize;
169 ddi.guidInstance = GUID_SysKeyboard;/* DInput's GUID */
170 ddi.guidProduct = DInput_Wine_Keyboard_GUID; /* Vendor's GUID */
171 if (version >= 8)
172 ddi.dwDevType = DI8DEVTYPE_KEYBOARD | (DI8DEVTYPEKEYBOARD_UNKNOWN << 8);
173 else
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) {
182 DWORD dwSize;
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));
192 ddi.dwSize = dwSize;
193 ddi.guidInstance = GUID_SysKeyboard;/* DInput's GUID */
194 ddi.guidProduct = DInput_Wine_Keyboard_GUID; /* Vendor's GUID */
195 if (version >= 8)
196 ddi.dwDevType = DI8DEVTYPE_KEYBOARD | (DI8DEVTYPEKEYBOARD_UNKNOWN << 8);
197 else
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)
207 if (id != 0)
208 return FALSE;
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);
217 return TRUE;
220 return FALSE;
223 static BOOL keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, int version, int id)
225 if (id != 0)
226 return FALSE;
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);
235 return TRUE;
238 return FALSE;
241 static SysKeyboardImpl *alloc_device(REFGUID rguid, LPVOID kvt, IDirectInputImpl *dinput)
243 SysKeyboardImpl* newDevice;
244 DWORD kbd_users;
246 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboardImpl));
247 newDevice->lpVtbl = kvt;
248 newDevice->ref = 1;
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);
260 return newDevice;
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);
275 return DI_OK;
276 } else
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);
293 return DI_OK;
294 } else
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;
311 ULONG ref;
312 DWORD kbd_users;
314 ref = InterlockedDecrement(&(This->ref));
315 if (ref)
316 return ref;
318 EnterCriticalSection(&keyboard_crit);
319 kbd_users = InterlockedDecrement(&keyboard_users);
320 if (0 == kbd_users) {
321 UnhookWindowsHookEx( keyboard_hook );
322 keyboard_hook = 0;
324 LeaveCriticalSection(&keyboard_crit);
326 /* Free the data queue */
327 HeapFree(GetProcessHeap(),0,This->buffer);
329 DeleteCriticalSection(&(This->crit));
331 HeapFree(GetProcessHeap(),0,This);
332 return DI_OK;
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);
351 if (This->acquired)
352 return DIERR_INVALIDPARAM;
354 This->buffersize = pd->dwData;
356 break;
358 default:
359 WARN("Unknown type %ld\n",(DWORD)rguid);
360 break;
363 return DI_OK;
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);
382 if (This->acquired)
383 return DIERR_INVALIDPARAM;
385 pd->dwData = This->buffersize;
387 break;
389 default:
390 WARN("Unknown type %ld\n",(DWORD)rguid);
391 break;
394 return DI_OK;
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)) {
413 int i;
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));
424 return DI_OK;
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)
454 if (dod != NULL)
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;
464 i++;
467 *entries = i;
469 if (This->overflow)
470 ret = DI_BUFFEROVERFLOW;
472 if (!(flags & DIGDD_PEEK))
474 /* Empty buffer */
475 This->count -= i;
476 This->start = (This->start + i) % This->buffersize;
477 This->overflow = FALSE;
480 LeaveCriticalSection(&(This->crit));
482 TRACE("Returning %ld events queued\n", *entries);
484 return ret;
487 static HRESULT WINAPI SysKeyboardAImpl_EnumObjects(
488 LPDIRECTINPUTDEVICE8A iface,
489 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
490 LPVOID lpvRef,
491 DWORD dwFlags)
493 SysKeyboardImpl *This = (SysKeyboardImpl *)iface;
494 DIDEVICEOBJECTINSTANCEA ddoi;
495 int i;
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);
501 TRACE("\n");
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;
511 ddoi.dwOfs = i;
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;
518 return DI_OK;
521 static HRESULT WINAPI SysKeyboardWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
522 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
523 LPVOID lpvRef,
524 DWORD dwFlags)
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);
544 if (This->acquired)
545 return S_FALSE;
547 This->acquired = 1;
549 if (current_lock != NULL) {
550 FIXME("Not more than one keyboard can be acquired at the same time.\n");
551 SysKeyboardAImpl_Unacquire(iface);
554 current_lock = This;
556 if (This->buffersize > 0) {
557 This->buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
558 This->buffersize * sizeof(*(This->buffer)));
559 This->start = 0;
560 This->count = 0;
561 This->overflow = FALSE;
562 } else {
563 This->buffer = NULL;
566 /*keyboard_hook = SetWindowsHookExW( WH_KEYBOARD_LL, KeyboardCallback, DINPUT_instance, 0 );*/
568 return DI_OK;
571 static HRESULT WINAPI SysKeyboardAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
573 SysKeyboardImpl *This = (SysKeyboardImpl *)iface;
574 TRACE("(this=%p)\n",This);
576 if (This->acquired == 0)
577 return DI_NOEFFECT;
579 /* No more locks */
580 if (current_lock == This)
581 current_lock = NULL;
582 else
583 ERR("this != current_lock\n");
585 /* Unacquire device */
586 This->acquired = 0;
588 if (This->buffersize >= 0) {
589 HeapFree(GetProcessHeap(), 0, This->buffer);
590 This->buffer = NULL;
593 return DI_OK;
596 static HRESULT WINAPI SysKeyboardAImpl_SetEventNotification(LPDIRECTINPUTDEVICE8A iface,
597 HANDLE hnd) {
598 SysKeyboardImpl *This = (SysKeyboardImpl *)iface;
600 TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
602 This->hEvent = hnd;
603 return DI_OK;
606 /******************************************************************************
607 * GetCapabilities : get the device capablitites
609 static HRESULT WINAPI SysKeyboardAImpl_GetCapabilities(
610 LPDIRECTINPUTDEVICE8A iface,
611 LPDIDEVCAPS lpDIDevCaps)
613 SysKeyboardImpl *This = (SysKeyboardImpl *)iface;
614 DIDEVCAPS devcaps;
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);
627 else
628 devcaps.dwDevType = DIDEVTYPE_KEYBOARD | (DIDEVTYPEKEYBOARD_UNKNOWN << 8);
629 devcaps.dwAxes = 0;
630 devcaps.dwButtons = WINE_DINPUT_KEYBOARD_MAX_KEYS;
631 devcaps.dwPOVs = 0;
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);
640 return DI_OK;
643 /******************************************************************************
644 * GetObjectInfo : get information about a device object such as a button
645 * or axis
647 static HRESULT WINAPI
648 SysKeyboardAImpl_GetObjectInfo(
649 LPDIRECTINPUTDEVICE8A iface,
650 LPDIDEVICEOBJECTINSTANCEA pdidoi,
651 DWORD dwObj,
652 DWORD dwHow)
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");
662 return DI_OK;
665 memset(pdidoi, 0, dwSize);
666 memset(&ddoi, 0, sizeof(ddoi));
668 ddoi.dwSize = dwSize;
669 ddoi.guidType = GUID_Key;
670 ddoi.dwOfs = dwObj;
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);
679 return DI_OK;
682 static HRESULT WINAPI SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
683 LPDIDEVICEOBJECTINSTANCEW pdidoi,
684 DWORD dwObj,
685 DWORD dwHow)
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");
695 return DI_OK;
698 memset(pdidoi, 0, dwSize);
699 memset(&ddoi, 0, sizeof(ddoi));
701 ddoi.dwSize = dwSize;
702 ddoi.guidType = GUID_Key;
703 ddoi.dwOfs = dwObj;
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);
712 return DI_OK;
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");
727 return DI_OK;
730 fill_keyboard_dideviceinstanceA(pdidi, This->dinput->version);
732 return DI_OK;
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");
742 return DI_OK;
745 fill_keyboard_dideviceinstanceW(pdidi, This->dinput->version);
747 return DI_OK;
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))
788 #else
789 # define XCAST(fun) (void*)
790 #endif
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
827 #undef XCAST