public List <InputDeviceEvent> GetEvents() { try { ms = mouse.GetCurrentState(); } catch { System.Diagnostics.Debug.WriteLine("Mouse removed!"); return(null); } // At the moment, not returning axis, as not needed.. bool[] buttons = ms.Buttons; List <InputDeviceEvent> events = new List <InputDeviceEvent>(); for (int i = 0; i < butstate.Length; i++) { bool s = buttons[i]; if (s != butstate[i]) { butstate[i] = s; //System.Diagnostics.Debug.WriteLine("But " + (i+1) + "=" + s); events.Add(new InputDeviceEvent(this, i + 1, butstate[i])); // 1..N } } return((events.Count > 0) ? events : null); }
public override void Update(IEnumerable <Entity> entities) { mouse.GetCurrentState(ref currentState); ScrollWheelValue = currentState.Z / MouseWheelDivider; UpdateMousePosition(); UpdateMouseButtons(); base.Update(entities); }
public void UpdateMouseState() { LastState = CurrentState; CurrentState = _Mouse.GetCurrentState(); if (LockMouse && FormHasFocus) { Cursor.Position = Point; } }
/// <summary> /// Collect the current data from the device /// </summary> public override void GetData( ) { // Make sure there is a valid device. if (null == m_device) { return; } // Poll the device for info. try { m_device.Poll( ); } catch (SharpDXException e) { if ((e.ResultCode == ResultCode.NotAcquired) || (e.ResultCode == ResultCode.InputLost)) { // Check to see if either the app needs to acquire the device, or // if the app lost the device to another process. try { // Acquire the device - if the (main)window is active if (Activated) { m_device.Acquire( ); } } catch (SharpDXException) { // Failed to acquire the device. This could be because the app doesn't have focus. return; // EXIT unaquired } } else { log.Error("Unexpected Poll Exception", e); return; // EXIT see ex code } } // Get the state of the device - retaining the previous state to find the lates change m_prevState = m_state; try { m_state = m_device.GetCurrentState( ); } // Catch any exceptions. None will be handled here, // any device re-aquisition will be handled above. catch (SharpDXException) { return; } }
public void Run() { gameTimer = Stopwatch.StartNew(); frameTimer = new Stopwatch(); RenderLoop.Run(renderForm, () => { double deltaTime = frameTimer.ElapsedTicks / (double)Stopwatch.Frequency; frameTimer.Restart(); frameTime += deltaTime; frameCount++; if (frameTime > 1) { frameTime = 0; Debug.FPS = frameCount; frameCount = 0; } Debug.BeginFrame(); Profiler p = Profiler.Begin("Frame"); Profiler.Begin("Update"); #region input state update if (renderForm.Focused) { Input.ks = keyboard.GetCurrentState(); if (Input.lastks == null) { Input.lastks = Input.ks; } } Input.ms = mouse.GetCurrentState(); if (Input.lastms == null) { Input.lastms = Input.ms; } Input.MousePos = realMousePos; #endregion Update(deltaTime); renderer.ScreenToWorld(Input.MousePos, renderer.ActiveCamera, out Input.MouseRayOrigin, out Input.MouseRayDirection); #region input state update Input.lastks = Input.ks; Input.lastms = Input.ms; Input.LastMousePos = Input.MousePos; #endregion Profiler.End(); Profiler.Begin("Draw"); Draw(); Profiler.End(); #if DEBUG Debug.EndFrame(p.Stopwatch.Elapsed.TotalSeconds); if (Debug.DrawDebug) { renderer.D2DContext.BeginDraw(); Debug.Draw2D(renderer); Profiler.End(); // Draw profiler //int py = frameProfiler.TotalChildren()*Profiler.lineHeight + Profiler.lineHeight; //renderer.D2DContext.FillRectangle(new RawRectangleF(renderer.ResolutionX - 360, 5, renderer.ResolutionX, 40 + py + 5), renderer.Brushes["TransparentBlack"]); //frameProfiler.Draw(renderer, new RawRectangleF(renderer.ResolutionX - 350, 10, renderer.ResolutionX - 10, 40)); float r = renderer.ResolutionX * .075f; p.DrawCircle(renderer, new Vector2(renderer.ResolutionX - r - 10, renderer.ResolutionY - r - 10), r); renderer.D2DContext.EndDraw(); } else { Profiler.End(); } #endif renderer.Present(); }); }