locohost Posted November 13, 2018 Share Posted November 13, 2018 I'm trying to figure out how to check for Ctrl key + an arrow key down at same time. I can check for arrows by themselves easy enough. I can add a listener for 'keydown_CTRL'. But I can't figure out how to check for both at same time. i.e.: if (Ctrl.isDown && rightArrow.isDown) { then do move right stuff... }. How do I do this? Thank you very much for helping :-) Mark Link to comment Share on other sites More sharing options...
rich Posted November 14, 2018 Share Posted November 14, 2018 this.input.keyboard.on('keydown_A', function (event) { if (event.ctrlKey) { console.log('A + CTRL'); } else if (event.altKey) { console.log('A + ALT'); } else if (event.shiftKey) { console.log('A + Shift'); } else { console.log('A without modifier'); } }); Befive.Info and rex 2 Link to comment Share on other sites More sharing options...
locohost Posted November 14, 2018 Author Share Posted November 14, 2018 Thank you @rich ! Link to comment Share on other sites More sharing options...
locohost Posted November 18, 2018 Author Share Posted November 18, 2018 Sadly, I'm striking out on this. Using @rich's advice I can make single Ctrl+Arrow keys happen, but they always fire just once and you have to keep repeatedly clicking the arrow. So they're not really "down" events like syntax suggests. How can I hold down Ctrl+Arrow and the event keep firing while they're both down? Thanks for helping! ? Link to comment Share on other sites More sharing options...
locohost Posted November 18, 2018 Author Share Posted November 18, 2018 Ok I see part of the problem. The Ctrl key down does keep firing repeatedly as I need, but as soon as you add the Arrow key down, it stops. So how do we code a check for Ctrl+Arrow down simultaneously and they fire continuously until one of key combo is released? Is there a Phaser 3 example that shows this? Link to comment Share on other sites More sharing options...
locohost Posted November 18, 2018 Author Share Posted November 18, 2018 Ok so "keydown_UP" is definitely not a up-arrow-held-down event. This code is in a create method. It only fires once... this.gameScene.input.keyboard.on('keydown_UP', (e) => { console.log('KeyUp is down...'); if (e.ctrlKey) { this.scroll(0); } }, this); Link to comment Share on other sites More sharing options...
locohost Posted November 18, 2018 Author Share Posted November 18, 2018 Ok, if you move it into an update method, it seems to work but fires at 1 million miles per hour ? Link to comment Share on other sites More sharing options...
locohost Posted November 18, 2018 Author Share Posted November 18, 2018 This is also definitely not a keydown event. Fires only once while arrow is held down... this.gameScene.input.keyboard.on('keydown', (e) => { // console.dir(e); if (e.keyCode === 38) { this.scroll(0); } if (e.keyCode === 39) { this.scroll(1); } if (e.keyCode === 40) { this.scroll(2); } if (e.keyCode === 37) { this.scroll(3); } // if (e.ctrlKey) { console.log('Ctrl is down...'); } // if (e.ctrlKey) { // if (this.cursors.up.isDown) { this.scroll(0); } // } }); Link to comment Share on other sites More sharing options...
locohost Posted November 18, 2018 Author Share Posted November 18, 2018 Ugh, Ok I found the Phaser 3 example needed. I'm dumb. Sorry for the unnecessary posts. Here is code needed... update() { if (this.cursors.up.isDown) { if (this.cursors.up.ctrlKey) { this.scroll(0); } } else if (this.cursors.down.isDown) { if (this.cursors.down.ctrlKey) { this.scroll(2); } } else if (this.cursors.left.isDown) { if (this.cursors.right.ctrlKey) { this.scroll(3); } } else if (this.cursors.right.isDown) { if (this.cursors.right.ctrlKey) { this.scroll(1); } } } Link to comment Share on other sites More sharing options...
Recommended Posts