public void RemoveKey(KeyButton button) { keyButtons.Remove(button); button.Activated -= button_Activated; button.HoverLost -= button_HoverLost; button.HoverGained -= button_HoverGained; }
void button_Activated(KeyButton sender) { if (KeyIsChar(sender.Key)) { //stringBuilder.Append(ConvertCodeToChar(sender.Key.ToString())); stringBuilder.Append(sender.Text); } else { // look for our special case strings! if (sender.Key == KeyCode.Backspace) { if (stringBuilder.Length > 0) { stringBuilder.Remove(stringBuilder.Length - 1, 1); } } else if (sender.Key == KeyCode.Space) { stringBuilder.Append(" "); } else if ((sender.Key == KeyCode.LeftShift) || (sender.Key == KeyCode.RightShift)) { ChangeMode(); } } Contents = stringBuilder.ToString(); if (TextOut != null) { TextOut.text = Contents; } }
/// <summary> /// キーボードの表示の更新 /// </summary> void ChangeSelectKeyborde(string kana) { //現在のキーボードの表示を修正する if (_selectedKey != null) { _selectedKey.ResetKey(); } //該当するキー KanaKeyMapInfo info = _model.KanaKeyMapInfoData[kana]; _keyButtons[info.typeKey].SelectKey(kana); //現在のキーボードの参照更新 _selectedKey = _keyButtons[info.typeKey]; //シフトの表示 _rightShiftButton.ResetKey(); _leftShiftButton.ResetKey(); if (info.rightShift == 1) { _rightShiftButton.SelectKey(); } else if (info.leftShift == 1) { _leftShiftButton.SelectKey(); } }
public void AddKey(KeyButton button) { keyButtons.Add(button); button.Activated += button_Activated; button.HoverLost += button_HoverLost; button.HoverGained += button_HoverGained; }
public void AddRandomKeyToPress() { KeyButton key = RandomizeKey(); key.SetToPress(); _keyToPressList.Add(key); }
/// <summary> /// 同步按键对,像 LShiftKey(左shift键) 和 RShiftKey(右shift键)。 /// </summary> void SyncKeyPairs(KeyButton btn) { if (btn == keyButtonLShift) { keyButtonRShift.IsPressed = keyButtonLShift.IsPressed; } if (btn == keyButtonRShift) { keyButtonLShift.IsPressed = keyButtonRShift.IsPressed; } if (btn == keyButtonLAlt) { keyButtonRAlt.IsPressed = keyButtonLAlt.IsPressed; } if (btn == keyButtonRAlt) { keyButtonLAlt.IsPressed = keyButtonRAlt.IsPressed; } if (btn == keyButtonLControl) { keyButtonRControl.IsPressed = keyButtonLControl.IsPressed; } if (btn == keyButtonRControl) { keyButtonLControl.IsPressed = keyButtonRControl.IsPressed; } }
public KeyButton AddRandomUsedKey(bool isLeft) { KeyButton key = isLeft ? RandomizeLeftKey() : RandomizeRightKey(); _keysUsed.Add(key); return(key); }
public static void RefreshActionInfo() { var Buttons = JsonConvert.DeserializeObject <List <object> >(File.ReadAllText("KeyButtons.json")); CurrentProfile.Buttons.Clear(); foreach (var item in Buttons) { JObject Button = item as JObject; var KeyButton = new KeyButton(); KeyButton.Id = Button.Value <int>("Id"); KeyButton.Name = Button.Value <string>("Name"); switch (Button.Value <string>("ActionType")) { case "1": KeyButton.Action = Button.Value <JObject>("Action").ToObject <HotKeyAction>(); break; case "2": KeyButton.Action = Button.Value <JObject>("Action").ToObject <HotkeySwitchAction>(); break; case "3": KeyButton.Action = Button.Value <JObject>("Action").ToObject <WebSiteAction>(); break; case "4": KeyButton.Action = Button.Value <JObject>("Action").ToObject <OpenFileAction>(); break; case "5": KeyButton.Action = Button.Value <JObject>("Action").ToObject <MultimediaAction>(); break; default: break; } CurrentProfile.Buttons.Add(KeyButton); } }
private void GetActions(List <object> Buttons) { foreach (var item in Buttons) { JObject Button = item as JObject; var KeyButton = new KeyButton(); KeyButton.Id = Button.Value <int>("Id"); KeyButton.Name = Button.Value <string>("Name"); switch (Button.Value <string>("ActionType")) { case "1": KeyButton.Action = Button.Value <JObject>("Action").ToObject <HotKeyAction>(); break; case "2": KeyButton.Action = Button.Value <JObject>("Action").ToObject <HotkeySwitchAction>(); break; case "3": KeyButton.Action = Button.Value <JObject>("Action").ToObject <WebSiteAction>(); break; case "4": KeyButton.Action = Button.Value <JObject>("Action").ToObject <OpenFileAction>(); break; case "5": KeyButton.Action = Button.Value <JObject>("Action").ToObject <MultimediaAction>(); break; default: break; } CurrentProfile.Buttons.Add(KeyButton); } }
// CL_KeyState // // Returns 0.25 if a key was pressed and released during the frame, // 0.5 if it was pressed and held // 0 if held then released, and // 1.0 if held for the entire time static float KeyState(ref KeyButton key) { bool impulsedown = (key.state & 2) != 0; bool impulseup = (key.state & 4) != 0; bool down = key.IsDown;// ->state & 1; float val = 0; if (impulsedown && !impulseup) { if (down) { val = 0.5f; // pressed and held this frame } else { val = 0; // I_Error (); } } if (impulseup && !impulsedown) { if (down) { val = 0; // I_Error (); } else { val = 0; // released this frame } } if (!impulsedown && !impulseup) { if (down) { val = 1.0f; // held the entire frame } else { val = 0; // up the entire frame } } if (impulsedown && impulseup) { if (down) { val = 0.75f; // released and re-pressed this frame } else { val = 0.25f; // pressed and released this frame } } key.state &= 1; // clear impulses return(val); }
public KeyButton RandomizeRightKey() { int i = Random.Range(0, _freeRightKeyList.Count); KeyButton freeKey = _freeRightKeyList[i]; _freeRightKeyList.RemoveAt(i); return(freeKey); }
protected void OnButtonRelease(object sender, ButtonReleaseEventArgs args) { KeyButton k = sender as KeyButton; int pos = entry.Position; entry.InsertText(k.text, ref pos); ++entry.Position; }
public bool GetButton(KeyButton button) { if (InputLock) { return(false); } return(Input.GetKey(inputs[button])); }
public void ReleaseRandomKeyToPress() { if (_keyToPressList.Count > 0) { int i = Random.Range(0, _keyToPressList.Count); KeyButton freeKey = _keyToPressList[i]; ReleaseKeyToPress(freeKey); } }
public virtual void OnKeyPressed(GameObject selectedObject) { KeyButton keyBut = selectedObject.GetComponent <KeyButton>(); if (keyBut != null && KeyPressed != null) { KeyPressed(keyBut); } }
public void KeyboardButton(KeyButton button) { Message.Add(button.Icon); button.DisableButton(); GameObject image = LoadSprite(button.Icon); image.transform.SetParent(MessageText.transform); image.transform.localEulerAngles = Vector3.zero; image.transform.localScale = new Vector3(1, 1, 1); }
public void when_execute() { Contexts contexts = null; Mock <IInputService> inputServiceMock = null; InputSystem inputSystem = null; before = () => { contexts = new Contexts(); inputServiceMock = new Mock <IInputService>(); inputSystem = new InputSystem(contexts, inputServiceMock.Object); inputSystem.Initialize(); }; new Each <bool, bool, bool>() { { false, true, true }, { true, false, false } }.Do((isUp, isDown, isPressed) => { context["Given key button state: isUp: {0}, isDown: {1}, isPressed: {2}".With(isUp, isDown, isPressed)] = () => { before = () => { KeyButton keyButton = new KeyButton(() => isUp, () => isDown, () => isPressed); inputServiceMock.SetupGet(x => x.LeftButton).Returns(keyButton); inputServiceMock.SetupGet(x => x.JumpButton).Returns(keyButton); inputServiceMock.SetupGet(x => x.RightButton).Returns(keyButton); inputSystem.Execute(); }; it["Right component must have a value: isUp: {0}, isDown: {1}, isPressed: {2}".With(isUp, isDown, isPressed)] = () => { contexts.input.inputEntity.right.isUp.should_be(isUp); contexts.input.inputEntity.right.isPressed.should_be(isPressed); contexts.input.inputEntity.right.isDown.should_be(isDown); }; it["Left component must have a value: isUp: {0}, isDown: {1}, isPressed: {2}".With(isUp, isDown, isPressed)] = () => { contexts.input.inputEntity.left.isUp.should_be(isUp); contexts.input.inputEntity.left.isPressed.should_be(isPressed); contexts.input.inputEntity.left.isDown.should_be(isDown); }; it["Jump component must have a value: isUp: {0}, isDown: {1}, isPressed: {2}".With(isUp, isDown, isPressed)] = () => { contexts.input.inputEntity.jump.isUp.should_be(isUp); contexts.input.inputEntity.jump.isPressed.should_be(isPressed); contexts.input.inputEntity.jump.isDown.should_be(isDown); }; }; }); }
private void updateBindTarget() { if (bindTarget != null) { bindTarget.IsBinding = false; } bindTarget = buttons.FirstOrDefault(b => b.IsHovered) ?? buttons.FirstOrDefault(); if (bindTarget != null) { bindTarget.IsBinding = true; } }
public void GenerateKeys() { int i, j, idx; // First lets wipe out our old children. for (i = gameObject.transform.childCount; i > 0; i--) { Transform child = gameObject.transform.GetChild(i - 1); GameObject.DestroyImmediate(child.gameObject); } rowContainers.Clear(); // Create the rows for (i = 0; i < Rows; i++) { GameObject newRow = new GameObject(); newRow.transform.parent = this.transform; newRow.name = "Row_" + i; rowContainers.Add(newRow); float rowOffset = (Rows / 2) - i; // Create the keys for (j = 0; j < Columns; j++) { string keyText = keyRows[i][j]; if (keyText != "") { GameObject newKey = GameObject.Instantiate(KeyPrefab) as GameObject; newKey.transform.parent = newRow.transform; idx = (i * Columns) + j; newKey.name = "Key_" + idx; KeyButton keyBut = newKey.GetComponent <KeyButton>(); keyBut.Character = keyBut.KeyText.text = keyText; KeyWidth = newKey.GetComponent <Collider>().bounds.size.x; KeyHeight = newKey.GetComponent <Collider>().bounds.size.y; float colOffset = j - (Columns / 2); float xOffset = colOffset * (KeyWidth + (Margin / 2)); newKey.transform.localPosition = new Vector3(xOffset, 0.0f, 0.0f); } } float yOffset = rowOffset * (KeyHeight + (Margin / 2)); newRow.transform.localPosition = new Vector3(0.0f, yOffset, 0.0f); } }
public void OnClick() { if (selectedButton != null) { selectedButton.UpdateText(); } selectedButton = this; if (mKeyText == null) { mKeyText = GetComponentInChildren <Text>(); } mKeyText.text = "..."; }
public void ReleaseKeyToPress(KeyButton keyButton) { if (_keyToPressList.Contains(keyButton)) { _keyToPressList.Remove(keyButton); keyButton.UnsetToPress(); if (VerifyButtonSide(keyButton.key)) { _freeLeftKeyList.Add(keyButton); } else { _freeRightKeyList.Add(keyButton); } } }
private void SetInput(CustomInput input) { switch (keyIndex) { case 0: keyMapping.primaryInput = input; break; case 1: keyMapping.secondaryInput = input; break; } UpdateText(); selectedButton = null; }
static void KeyUp(ref KeyButton b) { int k; string c = Cmd.Argv(1); if (!String.IsNullOrEmpty(c)) { k = int.Parse(c); } else { // typed manually at the console, assume for unsticking, so clear all b.down0 = b.down1 = 0; b.state = 4; // impulse up return; } if (b.down0 == k) { b.down0 = 0; } else if (b.down1 == k) { b.down1 = 0; } else { return; // key up without coresponding down (menu pass through) } if (b.down0 != 0 || b.down1 != 0) { return; // some other key is still holding it down } if ((b.state & 1) == 0) { return; // still up (this should not happen) } b.state &= ~1; // now up b.state |= 4; // impulse up }
/// <summary> /// 处理特殊按键,例如 “AppsKey”。 /// </summary> bool ProcessSpecialKey(KeyButton btn) { bool handled = true; switch (btn.Key) { // 使用 “Shift+F10” 模拟 Apps 键。 case Keys.Apps: UserInteraction.KeyboardInput.SendKey( new int[] { (int)Keys.ShiftKey }, (int)Keys.F10); break; default: handled = false; break; } return(handled); }
/// <summary> /// Sets the primary or secondary input to the selected input from the user. /// </summary> /// <param name="input">Input from any device or axis (e.g. Joysticks, Mouse, Keyboard)</param> private void SetInput(CustomInput input) { switch (keyIndex) { case 0: keyMapping.primaryInput = input; break; case 1: keyMapping.secondaryInput = input; break; } UpdateText(); //Enable this for auto-saving. To complete auto-saving, enable the comments in SettingsMode.cs > OnLoadClick(). Controls.Save(); selectedButton = null; }
public void SinglePLayerControllerFactoryTest() { StaticServiceLocator.AddService <IControllerSettings>(new ControllerSettings()); var controller = new SinglePlayerControllerFactory(); controller.CreateEntityController(new BaseMovable(), new EightWayPossibleMovement(new CrowDistance()), new MoverManager()); const Buttons buttons = Buttons.A; controller.AddGamePadButton(new List <IButtonAble>(), buttons); controller.AddKeyBoardButton(new List <IButtonAble>(), Keys.A); var button = new KeyButton(Keys.A); var smart = new SmartController(); smart.AddButton(new BaseSmartButton(button)); smart.Update(new GameTime()); }
static void KeyDown(ref KeyButton b) { int k; string c = Cmd.Argv(1); if (!String.IsNullOrEmpty(c)) { k = int.Parse(c); } else { k = -1; // typed manually at the console for continuous down } if (k == b.down0 || k == b.down1) { return; // repeating key } if (b.down0 == 0) { b.down0 = k; } else if (b.down1 == 0) { b.down1 = k; } else { Con.Print("Three keys down for a button!\n"); return; } if ((b.state & 1) != 0) { return; // still down } b.state |= 1 + 2; // down + impulse down }
private void finalise() { if (bindTarget != null) { store.Update(bindTarget.KeyBinding); bindTarget.IsBinding = false; Schedule(() => { // schedule to ensure we don't instantly get focus back on next OnMouseClick (see AcceptFocus impl.) bindTarget = null; }); } if (HasFocus) { GetContainingInputManager().ChangeFocus(null); } pressAKey.FadeOut(300, Easing.OutQuint); pressAKey.BypassAutoSizeAxes |= Axes.Y; }
private void finalise() { if (bindTarget != null) { store.Update(bindTarget.KeyBinding); bindTarget.IsBinding = false; Schedule(() => { // schedule to ensure we don't instantly get focus back on next OnMouseClick (see AcceptFocus impl.) bindTarget = null; }); } if (HasFocus) { GetContainingInputManager().ChangeFocus(null); } pressAKey.FadeOut(300, Easing.OutQuint); pressAKey.Padding = new MarginPadding { Top = height, Bottom = -pressAKey.DrawHeight }; }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); KeyButton button = GetActiveButton(e.X, e.Y, out _row, out _col); if (null != button) { bool sameKey = _downKey == button; _activeButton = button; DrawKey(sameKey && _timer.Enabled); } _downKey = null; _timer.Enabled = false; }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); // do hit detection here KeyButton activeButton = GetActiveButton(e.X, e.Y, out _row, out _col); if (_activeButton != activeButton) { _activeButton = activeButton; DrawKey(false); } }
private void HandleTapKeyPress(KeyButton activeButton, bool sendData) { // get all the set buttons here // Build modifiers here BluetoothHidWriter.KeyModifiers modifierState = GetModifierState(); char keyChar = (char)0; if (activeButton.HidKey == HidKeys.Enter) { _enteredKeys.Remove(0, _enteredKeys.Length); } else if (activeButton.HidKey == HidKeys.Back) { if (_enteredKeys.Length > 0) { _enteredKeys.Remove(_enteredKeys.Length - 1, 1); } } else { if (activeButton.IsChar) { char c = '\0'; if (0 != (modifierState & BluetoothHidWriter.KeyModifiers.LSHIFT)) { c = activeButton.ShiftKey[0]; } else { c = activeButton.Key[0]; } //if (char.IsLetterOrDigit(c)) { keyChar = c; _enteredKeys.Append(c); } } } DrawPreviousInput(true, activeButton); if (sendData) { _hidWriter.SendKeyPress((byte)modifierState, activeButton.HidKey); } for (int i = 0; i < _setButtons.Count; ++i) { if (0 != (_setButtons[i].Type & KeyButtonType.Hold) && _setButtons[i].Type != KeyButtonType.Shift) { _unsetButtons.Add(_setButtons[i]); _setButtons.RemoveAt(i); --i; } } using (Graphics g = this.CreateGraphics()) { DrawModifiers(g); } }
private static extern void RENDERDOC_SetCaptureKeys(ref KeyButton keys, int num);
private static extern void RENDERDOC_SetFocusToggleKeys(ref KeyButton keys, int num);
/* private KeyButton MapScanToButton(uint scanCode) { if (_scanToButton.ContainsKey(scanCode)) { return _scanToButton[scanCode]; } return null; } private KeyButton MapCharToButton(uint keyChar) { if (_charToButton.ContainsKey(keyChar)) { return _charToButton[keyChar]; } return null; } */ private void HandleKeyPress(KeyButton activeButton, bool sendData) { HandleKeyPress(activeButton, false, sendData); }
public void ReadXml(System.Xml.XmlReader reader) { reader.MoveToContent(); int row = 0; if (reader.IsStartElement("KeyButtonCollection") || reader.ReadToDescendant("KeyButtonCollection")) { int rows = Convert.ToInt32(reader.GetAttribute("rows")); _keys = new KeyButton[rows][]; if (reader.ReadToDescendant("KeyButtonRow")) { do { int col = 0; int cols = Convert.ToInt32(reader.GetAttribute("cols")); _keys[row] = new KeyButton[cols]; if (reader.ReadToDescendant("KeyButton")) { do { _keys[row][col] = new KeyButton(); _keys[row][col].ReadXml(reader); col++; } while (reader.ReadToNextSibling("KeyButton")); } row++; } while (reader.ReadToNextSibling("KeyButtonRow")); } } }
public void UpdatePlayerSixButtons() { DestroyList(); float maxNameWidth = 0; float contentHeight = 4; ReadOnlyCollection <KeyMapping> keys = InputControl.GetPlayerKeys(5); foreach (KeyMapping key in keys) { //======================================================================================== // Key Text vs Key Buttons //Key Text: The labels/text in the first column of the InputManager menu (see Options tab) //Key Buttons: The buttons in the second and third column of the Input Manager menu //======================================================================================== //Source: https://github.com/Gris87/InputControl #region Key text GameObject keyNameText = Instantiate(keyNamePrefab) as GameObject; keyNameText.name = key.name; RectTransform keyNameTextRectTransform = keyNameText.GetComponent <RectTransform>(); keyNameTextRectTransform.transform.SetParent(namesTransform); keyNameTextRectTransform.anchoredPosition3D = new Vector3(0, 0, 0); keyNameTextRectTransform.localScale = new Vector3(1, 1, 1); Text keyText = keyNameText.GetComponentInChildren <Text>(); keyText.text = key.name; float keyNameWidth = keyText.preferredWidth + 8; if (keyNameWidth > maxNameWidth) { maxNameWidth = keyNameWidth; } #endregion #region Key buttons GameObject keyButtons = Instantiate(keyButtonsPrefab) as GameObject; keyButtons.name = key.name; RectTransform keyButtonsRectTransform = keyButtons.GetComponent <RectTransform>(); keyButtonsRectTransform.transform.SetParent(keysTransform); keyButtonsRectTransform.anchoredPosition3D = new Vector3(0, 0, 0); keyButtonsRectTransform.localScale = new Vector3(1, 1, 1); for (int i = 0; i < 2; ++i) { KeyButton buttonScript = keyButtons.transform.GetChild(i).GetComponent <KeyButton>(); buttonScript.keyMapping = key; buttonScript.keyIndex = i; buttonScript.UpdateText(); } #endregion //============================================== contentHeight += 28; } RectTransform namesRectTransform = namesTransform.GetComponent <RectTransform>(); RectTransform keysRectTransform = keysTransform.GetComponent <RectTransform>(); RectTransform rectTransform = GetComponent <RectTransform>(); namesRectTransform.offsetMax = new Vector2(maxNameWidth, 0); keysRectTransform.offsetMin = new Vector2(maxNameWidth, 0); rectTransform.sizeDelta = new Vector2(0, contentHeight); GameObject.Find("SettingsMode").GetComponent <SettingsMode>().UpdateButtonStyle(); }
private void HandleKeyPress(KeyButton activeButton, bool hidePress, bool sendData) { if (!hidePress) { _activeButton = null; } if (null != activeButton) { // send click here if (0 != (activeButton.Type & KeyButtonType.Hold)) { if (_setButtons.Contains(activeButton)) { _unsetButtons.Add(activeButton); _setButtons.Remove(activeButton); } else { _unsetButtons.Remove(activeButton); _setButtons.Add(activeButton); } } switch (activeButton.Type & ~KeyButtonType.Hidden) { case KeyButtonType.Alternate: { _isAltSet = !_isAltSet; DrawKey(false); } break; case KeyButtonType.Control: { _isCtrlSet = !_isCtrlSet; DrawKey(false); } break; case KeyButtonType.Shift: { _isShiftSet = !_isShiftSet; if (!hidePress) { _tickRefresh = false; this.Refresh(); } else { _tickRefresh = true; } } break; case KeyButtonType.Windows: { _isWinSet = !_isWinSet; DrawKey(false); } break; case KeyButtonType.Tap: { HandleTapKeyPress(activeButton, sendData); _downKey = activeButton; _timer.Enabled = false; _timer.Enabled = true; } break; } if (0 != (activeButton.Type & KeyButtonType.Hold)) { BluetoothHidWriter.KeyModifiers modifierState = GetModifierState(); _hidWriter.SetModifierState((byte)modifierState); } } }
private void DrawPreviousInput(bool dataChanged, KeyButton activeButton) { if (Rectangle.Empty != _inputRect) { int startX = _inputRect.Left; int startY = _inputRect.Top; // TODO if (_rotation != 0) { if (_rotation == KeyboardRotation.ROT_270) { startY = this.Height - _inputRect.Right; startX = _inputRect.Top; } else { startY = _inputRect.Left; startX = this.Width - _inputRect.Bottom; } } using (Graphics g = this.CreateGraphics()) { if (dataChanged || null == _previousInputImage) { if (null != _previousInputImage) { _previousInputImage.Dispose(); } int width = this.Width; int height = _startY; width = _inputRect.Width; height = _inputRect.Height; using (Bitmap previousInputImage = new Bitmap(width, height)) { using (Graphics inputG = Graphics.FromImage(previousInputImage)) { inputG.Clear(Color.Gray); using (SolidBrush brush = new SolidBrush(this.ForeColor)) { string str = _enteredKeys.ToString(); SizeF size = inputG.MeasureString(str, this.Font); while (size.Width > width) { _enteredKeys.Remove(0, 2); str = _enteredKeys.ToString(); size = inputG.MeasureString(str, this.Font); } inputG.DrawString(str, this.Font, brush, 5, previousInputImage.Height / 2 - size.Height / 2); // TODO if (_rotation != 0) { _previousInputImage = new Bitmap(height, width); Imaging.RotateImage((int)_rotation, previousInputImage, _previousInputImage); } else { _previousInputImage = new Bitmap(previousInputImage); } } } } } if (null != activeButton) { Region r = new Region(new Rectangle(startX, startY, _previousInputImage.Width, _previousInputImage.Height)); r.Exclude(_eraseRegion); g.Clip = r; } g.DrawImage(_previousInputImage, startX, startY); } } }
public KeyButtonCollection(KeyButton[][] keys) { _keys = keys; }