public override Action Start() { IntPtr handle = Process.GetCurrentProcess().MainWindowHandle; KeyboardDevice = new Keyboard(DirectInputInstance); if (KeyboardDevice == null) throw new Exception("Failed to create keyboard device"); KeyboardDevice.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive); KeyboardDevice.Acquire(); KeyboardDevice.GetCurrentState(ref KeyState); setKeyPressedStrategy = new SetPressedStrategy(KeyDown, KeyUp); getKeyPressedStrategy = new GetPressedStrategy<int>(IsKeyDown); OnStarted(this, new EventArgs()); return null; }
/// <summary> /// Initialize the input. /// </summary> public static void ModuleInit() { directInput = new DirectInput(); keyboard = new Keyboard(directInput); keyboard.SetCooperativeLevel(Scene.Instance.GraphicsEngine.Form, CooperativeLevel.Nonexclusive | CooperativeLevel.Background); keyboard.Acquire(); mouse = new Mouse(directInput); mouse.SetCooperativeLevel(Scene.Instance.GraphicsEngine.Form, CooperativeLevel.Nonexclusive | CooperativeLevel.Background); mouse.Acquire(); s_lastFrameState = keyboard.GetCurrentState(); s_thisState = s_lastFrameState; s_lastFrameMouseState = mouse.GetCurrentState(); s_thisMouseState = s_lastFrameMouseState; }