Jump to content

Ctrl key + arrow down together: How do I check for this?


locohost
 Share

Recommended Posts

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

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

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

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...