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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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