• Gamedev
  • Actions & Inputs key combinations?

Hi All,

Is there a way to create key combinations, such as "shift-A" or "ctrl-A" instead of just "A" in the "Actions & Inputs" interface or programatically?

Thanks

    Only with the power of JavaScript's boolean operators XD The Actions & Inputs system is device-agnostic and doesn't include additional logic for keyboard modifiers.

    I would create a new action called CtrlModifier. Then, in the code, I would detect key combinations like this:

    if (ct.actions.CtrlModifier.down && ct.actions.Select.pressed) {
      selectAll();
    }

    The trick is looking for down state for the modifier but looking only for pressed state for the main key. This assumes that you don't need to listen for cases when someone holds A firstly and then presses Ctrl. But if you do, you would add an additional clause like the following:

    if ((ct.actions.CtrlModifier.down && ct.actions.Select.pressed) ||
        (ct.actions.CtrlModifier.pressed && ct.actions.Select.down)
    ) {
      selectAll();
    }

      Actually, it's a bit easier for the first case:

      if (ct.keyboard.ctrl && ct.actions.Select.pressed) {
        selectAll();
      }

        Thanks @CoMiGo. I considered that approach, but it seemed contrary to the idea that Actions should be device agnostic: an action might be a button on one device and a key combo on another.

        But this is what I’ll go with for now. My game has enough reliance on the keyboard that it likely wouldn’t translate well to another device anyway.

        lazza What are your other devices and overall input requirements? I think that any keyboard scheme nicely fits into gamepads... until you need to use all the 104 keys. Shoulders/triggers can act as modifiers for gamepad keys, and touch devices can benefit from movement speed and other gestures, though it ofc requires additional coding.

          Here goes…

          The game has 3 "characters" controlled by a single player, but only one is active at a time.

          1. Each character can move (in some fashion) in 4 directions (up, down, left, right). I'd like to use the arrow keys for this.
          2. The player can switch the "active" character. For that, I'd like to also use left and right, but with a modifier key (say, shift)
          3. Finally, each character can move into 1 of 3 depth positions (Z axis). For this, I'd like to use shift-up, shift-down.
          4. Lastly, there's an action key. I guess that would be "X" or spacebar.

          So all in all, even though there seems to be a lot of complexity, I've boiled it down to 6 keys: up, down, left, right, shift and x.

            I would do it this way:

            • For touch devices, three clickable portraits are on-screen to switch characters. For movement, a joystick is added for XY movement (or an on-screen D-pad) and two additional buttons for Z-axis movement, on the left side. The generic "action" button is on the right side. Portraits and the action button can be grouped, depending on how they're used.
            • For gamepads, XYAB (face buttons) are used for three characters + the action button. XY movement is made by a stick or a D-pad, Z movement is made by pressing shoulders and triggers.
            • btw, XYZ movement for a keyboard is oftentimes made with QWEASD buttons, where Q and E change depth. Space Engineers use Q and E for rotation in a 3D environment and Ctrl and Space for up/down motion.

              Wow. This is fantastic input (pun intended!)

              The clickable avatars idea fits perfectly. (I’m already using that as a heads up display that animates when you switch characters) but I hadn’t even thought of what the experience would be on a touch device.

                Write a Reply...