Do action if two buttons are pressed

I want to do an action if a user press at the same time UP and DOWN. Is there a way to do it? I've tried to do use a list like that : 

function onKeyPressed(evt)
    {
        btnSequence[1] = btnSequence[0];
        btnSequence[0] = evt.getKey();
        
        if (btnSequence[0] == 8 && btnSequence[1] == 13) {
            // DO ACTION
        }
        return true;
    }
    
function onKeyReleased(evt) 
    {
        btnSequence = [-1, -1] as Array<Number>;
        return true;
    }

However the DO ACTION part doesn't seam to run and it's hard to test since you can't in the simulator press two button at once.

  • Never seen anyone get something like this to work, and even trying to do your own detection of a long press is problematic.  Different devices already have long presses assigned to different system functions and then throw in devices with hotkey sequences that can trigger other things

  • since you can't in the simulator press two button at once.

    You can if you use the keyboard:

    KEY_UP = UP
    KEY_DOWN = DOWN
    KEY_MENU = M (even on a device which doesn't have a separate physical menu button :/)
    KEY_ESC = ESC
    KEY_ENTER = ENTER

    I tried modifying the Input SDK sample with your code and it kinda works. You have to hold down one button, wait a second or two, then hold down the second button. The problem is if you press the two keys too quickly in succession (or the same time *), then the onKeyPressed event doesn't fire for the 2nd one, but the onKeyReleased event does fire for the 2nd one, which prevents the 2-button press from being detected.

    (* ofc your code as written only really handles the case where UP is pressed first.)

    This might be fixable (in the sim at least) by also taking action in onKeyReleased (if the action wasn't taken in onKeyPressed).

    Another problematic case is when the user presses the key sequence itself too quickly in succession: UP + DOWN, UP + DOWN. In this case, the 1st press of DOWN might cancel the 2nd press of UP.

    Funnily enough, the detection of native 2-button hotkeys seems to be a bit finicky too - not as much as this, but you do have to press the 2 buttons "in a certain way" to get the input to be detected (like it seems that one button always has to be pressed first, you can't really press them both at the same time.)

    Anyway, I think this kind of thing is ok as long as:
    - you can get it to be detected reliably (this kind of thing might not work on very old devices like fr235, and the sim may not reflect it)

    - it's optional. I think users won't like it if a 2 button shortcut is required for some crucial app functionality, even if it never conflicts with a system or user hotkey.

    In this case, UP + DOWN doesn't conflict with any system or user-definable hotkeys (on any watches I've seen).

  • As a user I wouldn't like to use any 2-key shortcuts where the 2 keys are on the same side of the watch. Most certainly not when I wear the watch (24/7) and I am right handed so I wear the watch on my left arm, and the two buttons I have to press with my right hand are on the left side of the watch. The only way the up+down can be pressed is by totally hiding the screen with my right hand.

    BTW I even less would like to press 2 buttons on the same side if I don't wear the watch, but hold it, as then I would even push the watch to the side and with high probability cause it to fall.

  • Sounds like a bad idea.

    If the SDK doesn’t explicitly support it, it probably won’t be reliable. 

    It seems like Garmin’s idea for IQ isn’t “anything you can get away with”’(like a PC).

  • As a user I wouldn't like to use any 2-key shortcuts where the 2 keys are on the same side of the watch. Most certainly not when I wear the watch (24/7) and I am right handed so I wear the watch on my left arm, and the two buttons I have to press with my right hand are on the left side of the watch. The only way the up+down can be pressed is by totally hiding the screen with my right hand.

    BTW I even less would like to press 2 buttons on the same side if I don't wear the watch, but hold it, as then I would even push the watch to the side and with high probability cause it to fall.

    Yeah I think the reason UP + DOWN isn't a supported user-assignable hotkey combo is bc it's too hard to do. I was going to say something to do that effect, but I edited it out of my original response.

    To support your point, on a 5-button watch all of the two-key hotkey combos involve keys on opposite sides on the watch.

    At the same time, it might help if the OP's input requirements were relaxed such that:

    - the combo would be recognized regardless of whether UP or DOWN was pressed first (currently UP has to be pressed first)

    - the combo would be recognized on key release if it wasn't recognized on key press (to work around the issue where pressing two buttons in quick sequence causes the 2nd one to be ignored)

    Wearing the watch on my left hand, I can press UP + DOWN (with UP being held for about a second before DOWN is pressed) with my right hand, without covering the screen: I brace the top right corner of the watch with my index or  middle finger, then use my thumb to "roll over" the UP and DOWN buttons.

    Is it convenient? No. Am I liable to accidentally trigger the menu (hold UP) or music screen (hold DOWN)? Yes.

    Even the built in user-assignable hotkey combos are finicky, but their one saving grace is if you mess up the input so it's not recognized, *usually* you don't trigger another unintended action. e.g. I have a hotkey action assigned to DOWN + START: screenshot. I always enter this by pressing and holding DOWN, then pressing START. There's been times when I've pressed this and a screenshot *wasn't* taken, but I've almost never accidentally triggered the default START button action when pressing this combo during an activity. This goes back to the earlier observation of how the system seems to ignore two button presses that are close together. This seems to apply to native code as well. On a real watch, if I'm in an activity and I press DOWN (and release), then quickly press START, the START button is ignored. It could very well be that this is purposely done to avoid misinputs when the user tries to do a hotkey combo.

    If the SDK doesn’t explicitly support it, it probably won’t be reliable. 

    Even stuff that the SDK explicitly supports is often unreliable haha. onKeyPressed() and onKeyReleased() don't work in very old devices (e.g. fr230, fr235, fr735), and it's not reflected in the simulator (those events do work in the sim, for those devices.)

    Ofc that specific issue is less of a problem in 2024, but it's still the case that the simulator doesn't always reflect the real behavior of devices.