Jump to content
  • Advertisement
Sign in to follow this  
Northwind877

[SlimDX] DirectInput GetDeviceState

This topic is 2568 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I have a problem with the DirectInput in SlimDX. I only want to get input when the window is the current active window on the desktop. So I used following flags for my keyboard:

res = keyboard.SetCooperativeLevel(form, CooperativeLevel.Foreground | CooperativeLevel.Nonexclusive);
[font="Consolas"][font="Consolas"]res = keyboard.Acquire();

[/font][/font]But then I'm getting an Access denied error when I try to call:
[font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]KeyboardState[/font][/font][/font][font="Consolas"][font="Consolas"] keys = keyboard.GetCurrentState();

[/font][/font][font="Arial"]In one of my DirectX11 / C++ books I read that during the course of a game the input device may be lost. And it has following solution:

[font="Arial"]HRESULT hr =
keyboardDevice->GetDeviceState(sizeof(buffer),(LPVOID)&buffer);
if(FAILED(hr))
{
hr
= keyboardDevice->Acquire();

while(hr == DIERR_INPUTLOST)
{
hr
= mouseDevice->Acquire();
}
}
[/font]


But I can't find a GetDeviceState method in SlimDX. How can I find out if the input device is acquired?
[/font]There is just one method:public Result GetCurrentState( ref KeyboardState data)
But if the input device isn't acquired I can't get [font="Arial"]the[/font] KeyboardState I need..


Thank you!

Share this post


Link to post
Share on other sites
Advertisement
it works now :)


[font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"] [font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][font="Consolas"] (keyboard.Acquire().IsFailure)[/font][/font]
[font="Consolas"][font="Consolas"] {

keyboard.Acquire();
[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]return[/font][/font][/font][font="Consolas"][font="Consolas"];[/font][/font]

[font="Consolas"][font="Consolas"]}

[/font][/font][/font][/font][/font]

Share this post


Link to post
Share on other sites
Hey,

I initialize the keyboard the same way you do, so:
DirectInput dinput = new DirectInput();

CooperativeLevel cooperativeLevel = CooperativeLevel.Foreground | CooperativeLevel.Nonexclusive | CooperativeLevel.NoWinKey;
try
{
_Keyboard = new Keyboard(dinput);
_Keyboard.SetCooperativeLevel(WndHandle, cooperativeLevel);
}
catch (DirectInputException e)
{
MessageBox.Show(e.Message);
return;
}

_Keyboard.Acquire();


And to poll its state I do:
public KeyboardState Keyboard
{
get
{
if (_Keyboard.Acquire().IsFailure)
return new KeyboardState();

if (_Keyboard.Poll().IsFailure)
return new KeyboardState();

return _Keyboard.GetCurrentState();
}
}


That worked fine for me so far. Hope it helps!

EDIT: Oops, a little to late. ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!