PDA

View Full Version : DirectInput creating?!



hammer
03-06-2004, 01:22 PM
after i've created the input

DirectInput8Create(GetModuleHandle(nil),DIRECTINPU T_VERSION,IID_IDirectInput8,m_pDInput,nil);

i need to create a device right? so here it goes:


m_pDInput.CreateDevice(GUID_SysKeyboard, ?!?!?!?!?!?!?, NIL);
on the ?!?!?!?!? place i cant seem to understand what should stand???

ou and one last thing the variable should be like this, right?-> m_pDInput : IDirectInput;

i am using clootie dx9 headers

Alimonster
03-06-2004, 09:32 PM
The question mark part is the device you'll be creating - it's an out parameter, so... m_pDInput.CreateDevice(GUID_SysKeyboard, FKeyboardDevice, NIL);

where FKeyboardDevice is a IDirectInputDevice8, or whatever. You'd then use the keyboard device var to access the keyboard. Your input variable should be declared as IDirectInput (maybe a specific version, like IDirectInput8 - can't remember).

As a style note, Hungarian notation ("m_p") is frowned upon in the Delphi community. If possible, avoid it (although I understand that you may well be taking it from C++ example code).

Clootie
03-06-2004, 10:57 PM
var
g_pDI: IDirectInput8;
g_pKeyboard: IDirectInputDevice8;
begin
if bExclusive then
dwCoopFlags := DISCL_EXCLUSIVE
else
dwCoopFlags := DISCL_NONEXCLUSIVE;

if bForeground then
dwCoopFlags := dwCoopFlags or DISCL_FOREGROUND
else
dwCoopFlags := dwCoopFlags or DISCL_BACKGROUND;

// Disabling the windows key is only allowed only if we are in foreground nonexclusive
if bDisableWindowsKey and not bExclusive and bForeground then
dwCoopFlags := dwCoopFlags or DISCL_NOWINKEY;

// Create a DInput object
hr := DirectInput8Create( HInstance, DIRECTINPUT_VERSION,
IID_IDirectInput8, g_pDI, nil );

// Obtain an interface to the system keyboard device.
hr := g_pDI.CreateDevice( GUID_SysKeyboard, g_pKeyboard, nil );

// Set the data format to "keyboard format" - a predefined data format
//
// A data format specifies which controls on a device we
// are interested in, and how they should be reported.
//
// This tells DirectInput that we will be passing an array
// of 256 bytes to IDirectInputDevice::GetDeviceState.
hr := g_pKeyboard.SetDataFormat( c_dfDIKeyboard );

// Set the cooperativity level to let DirectInput know how
// this device should interact with the system and with other
// DirectInput applications.
hr := g_pKeyboard.SetCooperativeLevel( Handle, dwCoopFlags );

hammer
04-06-2004, 09:37 AM
10x for the info

but Clootie hr := g_pKeyboard.SetCooperativeLevel( Handle, dwCoopFlags );

how do i get the handle of an app created with Cmyd3dapplication ????

hammer
04-06-2004, 09:58 AM
i am such a blind dude
m_hWnd

btw Clootie is there some documentation on the clootie dx9 ?
cous i have to search most of the f() and vars in the headers which is not very fast :(

hammer
04-06-2004, 10:25 AM
and again its me another problem

type
TKeyBuff = array [0..256] of char;
var
KeyBuff : ^TKeyBuff;
and just a couple a lines down :

DirectInput8Create(GetModuleHandle(nil),DIRECTINPU T_VERSION,IID_IDirectInput8,m_pDInput,nil);

m_pDInput.CreateDevice(GUID_SysKeyboard, m_pDInputDevice, NIL);

m_pDInputDevice.SetDataFormat(c_dfDIKeyboard);

InputCoopFlags := DISCL_EXCLUSIVE +DISCL_FOREGROUND + DISCL_NOWINKEY;
m_pDInputDevice.SetCooperativeLevel(m_Hwnd,InputCo opFlags);
m_pDInputDevice.Acquire;

case m_pDInputDevice.GetDeviceState(sizeof(KeyBuff),Key Buff) of
DIERR_INVALIDPARAM : MessageBox(m_hwnd,'Invalid Parameters','',MB_OK);
DIERR_INPUTLOST : MessageBox(m_hwnd,'Input Lost','',MB_OK);
DIERR_NOTACQUIRED : MessageBox(m_hwnd,'Not Acquired','',MB_OK);
DIERR_NOTINITIALIZED : MessageBox(m_hwnd,'Not Initialized','',MB_OK);
E_PENDING : MessageBox(m_hwnd,'Pending','a',MB_OK );
end;

the code looks good and the compiler gives no error but when i run it
it gives me Invalid Parameters so my gues is that the getdevicestate is called with bad arguments but so far i couldnt fix it, help please

what am i doing wrong ????????????

Clootie
04-06-2004, 10:49 AM
btw Clootie is there some documentation on the clootie
cous i have to search most of the f() and vars in the headers which is not very fast
Yes, its' called MS DirectX SDK: http://msdn.microsoft.com/directx. But for D3DFramework there is not much of it.

About erros....
You need: TKeyBuff = array [0..255] of char;

hammer
05-06-2004, 07:03 AM
hm.. i still get invalid parameters any other ideas?????

Clootie
05-06-2004, 07:11 PM
sizeof(KeyBuff^) or sizeof(TKeyBuff)

hammer
06-06-2004, 06:04 AM
i get an access violation at dinput8.dll when i use sizeof(TKeyBuff) or sizeof(KeyBuff^)

i'm beggining to hate directinput.

Clootie
06-06-2004, 10:10 AM
This one is working correctly:
[background=#FFFFFF][normal=#000000][number=#0000FF][string=#0000FF][comment=#248F24][reserved=#000000]
procedure TForm1.Button1Click(Sender: TObject);
type
TKeyBuff = array [0..255] of char;
var
KeyBuff : TKeyBuff;
m_pDInput: IDirectInput8;
m_pDInputDevice: IDirectInputDevice8;
InputCoopFlags: DWORD;
begin
DirectInput8Create(GetModuleHandle(nil), DIRECTINPUT_VERSION, IID_IDirectInput8, m_pDInput, nil);

m_pDInput.CreateDevice(GUID_SysKeyboard, m_pDInputDevice, nil);

m_pDInputDevice.SetDataFormat(c_dfDIKeyboard);

InputCoopFlags := DISCL_EXCLUSIVE + DISCL_FOREGROUND + DISCL_NOWINKEY;
m_pDInputDevice.SetCooperativeLevel(Handle, InputCoopFlags);
m_pDInputDevice.Acquire;

case m_pDInputDevice.GetDeviceState(sizeof(KeyBuff),@Ke yBuff) of
DIERR_INVALIDPARAM : MessageBox(Handle,'Invalid Parameters','',MB_OK);
DIERR_INPUTLOST : MessageBox(Handle,'Input Lost','',MB_OK);
DIERR_NOTACQUIRED : MessageBox(Handle,'Not Acquired','',MB_OK);
DIERR_NOTINITIALIZED : MessageBox(Handle,'Not Initialized','',MB_OK);
Integer(E_PENDING): MessageBox(Handle,'Pending','a',MB_OK );
end;
end;
Look at http://groups.yahoo.com/group/JEDI-DirectXExamples/files/DirectInput/ for available Delphi DirectInput examples.

hammer
06-06-2004, 06:13 PM
it seems this one is working apperiantly i've misplaced the @ with a ^
thanks clootie but yet again i have a problem how do i convert

...
if (diKeys[DIK_ESCAPE] & 0x80) DoSomething();
...

Clootie
06-06-2004, 08:04 PM
Please, look at the link I posted above...
Where you can, for example, find this code:
for i := 0 to 255 do
begin
if (diks[i] and $80) <> 0 then
begin
strNewText := strNewText + Format('$%02x ', [i]);
end;
end;

hammer
06-06-2004, 09:47 PM
Clootie i've registered to the groups but the request need to be authorized by the admin or smth like that from the group so i coudnt look at the actual link.
sorry for the inconvenience.
and once more thanks for the help