• [SlimDX] DirectInput Lost Focus - Not attaching again...
    0 replies, posted
Hey...I hope someone can answer this: I have an input class and the input is perfect, but the second I switch away and back to the renderwindow, there is NO WAY to Attach() the devices again. I have tried: [code] Keyboard.Poll(); if (Result.Last.IsFailure()) { Attach(); } [/code] AND [code] if (Keyboard.Poll().IsFailure) { Attach(); } [/code] Here is the full thing... [code] using System; using System.Drawing; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Windows.Forms; using SlimDX; using SlimDX.DirectInput; using SlimDX.Windows; namespace Project { class Input { Globals Globals; DirectInput DirectInput; //IEnumerable<DeviceInstance> CurrentKeyboardDevice; //IEnumerable<DeviceInstance> CurrentMouseDevice; Keyboard Keyboard; Mouse Mouse; MouseState CurrentMouseState; MouseState PreviousMouseState = null; KeyboardState CurrentKeyboardState; KeyboardState PreviousKeyboardState; CooperativeLevel Levels; public Input(Globals _Globals) { Globals = _Globals; Attach(); } public bool Attach() { DirectInput = new DirectInput(); Keyboard = new Keyboard(DirectInput); Levels = new CooperativeLevel(); Levels |= CooperativeLevel.Nonexclusive; Levels |= CooperativeLevel.Foreground; Keyboard.SetCooperativeLevel(Globals.Render.RenderForm.Handle, Levels); Keyboard.Acquire(); CurrentKeyboardState = Keyboard.GetCurrentState(); Mouse = new Mouse(DirectInput); Mouse.SetCooperativeLevel(Globals.Render.RenderForm.Handle, Levels); Mouse.Acquire(); CurrentMouseState = Mouse.GetCurrentState(); //CurrentKeyboardDevice = DirectInput.GetDevices(DeviceClass.Keyboard, DeviceEnumerationFlags.AttachedOnly); //CurrentMouseDevice = DirectInput.GetDevices(DeviceClass.Pointer, DeviceEnumerationFlags.AttachedOnly); return true; } public void Update() { PreviousKeyboardState = CurrentKeyboardState; CurrentKeyboardState = Keyboard.GetCurrentState(); //Attach(); Keyboard.Poll(); if (Result.Last.IsFailure) { Attach(); } PreviousMouseState = CurrentMouseState; CurrentMouseState = Mouse.GetCurrentState(); //Attach(); Mouse.Poll(); if (Result.Last.IsFailure) { Attach(); } } public bool IsKeyDown(Key Key) { if (CurrentKeyboardState.IsPressed(Key)) { return true; } return false; } public bool WasKeyPressed(Key Key) { if (CurrentKeyboardState.IsReleased(Key)) { if (PreviousKeyboardState.IsPressed(Key)) { return true; } } return false; } public void Destroy() { Keyboard.Unacquire(); } public int MouseXC() { return CurrentMouseState.X; } public int MouseYC() { return CurrentMouseState.Y; } public bool MouseDown() { return CurrentMouseState.IsPressed(0); } public bool MouseDownRight() { return CurrentMouseState.IsPressed(1); } } } [/code] Its ugly, not finished, and semi works. I have searched google (Sorry Trolls :P), and have found a couple results. Needless to say...they don't seem to help. Thanks! EDIT: Or should I switch to the SlimDX raw input?
Sorry, you need to Log In to post a reply to this thread.