public override bool Poll() { lock (this) { if (!this.Attached) return false; } Device dev = this.Device; JoystickState state; try { dev.Poll(); state = dev.CurrentJoystickState; } catch (NotAcquiredException) { System.Diagnostics.Trace.TraceWarning("Device {0} ({1}) is not acquired.\n", this.Name, this.ID); return false; } List<ControllerKey> keys = new List<ControllerKey>(); byte[] btns = state.GetButtons(); if (null != btns && btns.Length > 0) { for (int i = 0; i < btns.Length; i++) { if (btns[i] > 0) keys.Add(new ControllerKey(i)); } } if (0 == state.X) keys.Add(new ControllerKey(101)); // Axis X left else if (65535 == state.X) keys.Add(new ControllerKey(102)); // Axis X right if (0 == state.Y) keys.Add(new ControllerKey(103)); // Axis Y up else if (65535 == state.Y) keys.Add(new ControllerKey(104)); // Axis Y down if (keys.Count > 0) { ControllerPressedEventArgs e = new ControllerPressedEventArgs(keys.ToArray()); #if DEBUG int axisRz = state.Rz; int axisRx = state.Rx; int axisX = state.X; int axisY = state.Y; e.sDebug = string.Format("Rz:{0}, Rx:{2}, X{2}, Y{3}", axisRz, axisRx, axisX, axisY); #endif this.Press(e); return true; } return false; }
/// <summary> /// To trigger the Pressed event. /// </summary> /// <param name="e"></param> public void Press(ControllerPressedEventArgs e) { if (Pressed != null) { //lock (Pressed) { Pressed(this, e); //} } }
// NOTICE: in controller thread public static void Controller_Pressed(object sender, ControllerPressedEventArgs e) { IController c = sender as IController; ControllerSettingInputDialog target = c.Target as ControllerSettingInputDialog; if (null != target) { target.PressedKeys = e.Keys; } c.Stop(); }
protected virtual void OnController_Pressed(object sender, ControllerPressedEventArgs e) { if (this.Status != EnumGameStatus.Running) return; IController c = sender as IController; string action = string.Empty; Player player; if (null != e.Keys && e.Keys.Count > 0) { lock (c) { action = c.Translate(e.Keys[0]); player = GetPlayer(c); } lock (player) { object act = null; action = action.ToUpper(); if (ActionMapping.TryGetValue(action, out act)) player.PlayFiled.Go(act); #if DEBUG player.PlayFiled.DebugString = e.sDebug; player.PlayFiled.RePaint(); #endif } } }