private async void ControllerAction_KeyDown(object sender, OVRKeyEventArgs e) { //win.KeyDownEvent{ value = win, new KeyEventArgs((EVRButtonId)e.ButtonId, e.Axis.x, e.Axis.y, e.IsLeft)); var config = new KeyConfig(); config.type = KeyTypes.Controller; config.actionType = KeyActionTypes.Hand; config.keyCode = -2; config.keyName = e.Name; config.isLeft = e.IsLeft; bool isStick = e.Name.Contains("Stick"); config.keyIndex = e.IsAxis == false ? -1 : NearestPointIndex(e.IsLeft, e.Axis.x, e.Axis.y, isStick); config.isTouch = e.IsTouch; if (e.IsAxis) { if (config.keyIndex < 0) { return; } if (e.IsLeft) { if (isStick) { lastStickLeftAxisPoint = config.keyIndex; } else { lastTouchpadLeftAxisPoint = config.keyIndex; } } else { if (isStick) { lastStickRightAxisPoint = config.keyIndex; } else { lastTouchpadRightAxisPoint = config.keyIndex; } } } if (doKeyConfig || doKeySend) { await controlWPFWindow.server.SendCommandAsync(new PipeCommands.KeyDown { Config = config }); } if (!doKeyConfig) { CheckKey(config, true); } }
private async void ControllerAction_KeyUp(object sender, OVRKeyEventArgs e) { //win.KeyUpEvent{ value = win, new KeyEventArgs((EVRButtonId)e.ButtonId, e.Axis.x, e.Axis.y, e.IsLeft)); var config = new KeyConfig(); config.type = KeyTypes.Controller; config.actionType = KeyActionTypes.Hand; config.keyCode = -2; config.keyName = e.Name; config.isLeft = e.IsLeft; bool isStick = e.Name.Contains("Stick"); config.keyIndex = e.IsAxis == false ? -1 : NearestPointIndex(e.IsLeft, e.Axis.x, e.Axis.y, isStick); config.isTouch = e.IsTouch; if (e.IsAxis && config.keyIndex != (isStick ? (e.IsLeft ? lastStickLeftAxisPoint : lastStickRightAxisPoint) : (e.IsLeft ? lastTouchpadLeftAxisPoint : lastTouchpadRightAxisPoint))) {//タッチパッド離した瞬間違うポイントだった場合 var newindex = config.keyIndex; config.keyIndex = (isStick ? (e.IsLeft ? lastStickLeftAxisPoint : lastStickRightAxisPoint) : (e.IsLeft ? lastTouchpadLeftAxisPoint : lastTouchpadRightAxisPoint)); //前のキーを離す if (doKeyConfig) { } // await server.SendCommandAsync(new PipeCommands.KeyUp { Config = config }); else { CheckKey(config, false); } config.keyIndex = newindex; if (config.keyIndex < 0) { return; } //新しいキーを押す if (doKeyConfig) { await controlWPFWindow.server.SendCommandAsync(new PipeCommands.KeyDown { Config = config }); } else { CheckKey(config, true); } } if (doKeyConfig || doKeySend) { } // await server.SendCommandAsync(new PipeCommands.KeyUp { Config = config }); if (!doKeyConfig) { CheckKey(config, false); } }
//タッチパッドやアナログスティックの変動 private async void ControllerAction_AxisChanged(object sender, OVRKeyEventArgs e) { if (e.IsAxis == false) { return; } var keyName = e.Name; if (keyName.Contains("Trigger")) { return; //トリガーは現時点ではアナログ入力無効 } if (keyName.Contains("Position")) { keyName = keyName.Replace("Position", "Touch"); //ポジションはいったんタッチと同じにする } bool isStick = keyName.Contains("Stick"); var newindex = NearestPointIndex(e.IsLeft, e.Axis.x, e.Axis.y, isStick); if ((isStick ? (e.IsLeft ? lastStickLeftAxisPoint : lastStickRightAxisPoint) : (e.IsLeft ? lastTouchpadLeftAxisPoint : lastTouchpadRightAxisPoint)) != newindex) {//ドラッグで隣の領域に入った場合 var config = new KeyConfig(); config.type = KeyTypes.Controller; config.actionType = KeyActionTypes.Hand; config.keyCode = -2; config.keyName = keyName; config.isLeft = e.IsLeft; config.keyIndex = (isStick ? (e.IsLeft ? lastStickLeftAxisPoint : lastStickRightAxisPoint) : (e.IsLeft ? lastTouchpadLeftAxisPoint : lastTouchpadRightAxisPoint)); config.isTouch = true; // e.IsTouch; //ポジションはいったんタッチと同じにする //前のキーを離す if (doKeyConfig || doKeySend) { } // await server.SendCommandAsync(new PipeCommands.KeyUp { Config = config }); if (!doKeyConfig) { CheckKey(config, false); } config.keyIndex = newindex; //新しいキーを押す if (doKeyConfig || doKeySend) { if (isSendingKey == false) { isSendingKey = true; await controlWPFWindow.server.SendCommandAsync(new PipeCommands.KeyDown { Config = config }); isSendingKey = false; } } if (!doKeyConfig) { CheckKey(config, true); } if (e.IsLeft) { if (isStick) { lastStickLeftAxisPoint = newindex; } else { lastTouchpadLeftAxisPoint = newindex; } } else { if (isStick) { lastStickRightAxisPoint = newindex; } else { lastTouchpadRightAxisPoint = newindex; } } } }