Isolating key commands

Greetings, all,

I’m working on having my sprite move, and I’m trying to keep key overlap from happening. What I mean is that, when I hit the “Right” key, I want ONLY that key command to work. But when I hit right and inadvertently hit “Up,” “Down,” etc., the sprite will act wonky. How do I ensure that no other keys interfere with the operation of a key command?

Thank you

Use a variable string to keep track of the key command. Set it to “” when no key is pressed, and set it to whatever command is for the key press only if it’s “”.

Then act on the contents of that variable.

Something like :

I tried that out. The only problem comes when I hit a pair of keys simultaneously, like the left/up key or the right/down key. The initial player stops, and I get a “ghost” that continues in the direction of the second hit key, and won’t stop.

What I basically need to do is to make the Key command exclusionary to any other key that would mess things up (in this case, preventing another direction key for movement from being inadvertently hit and causing the “character split” like I’m getting.

Then you’ve done something incorrectly, or differently. Those events are from a test project I created to answer your post, and works without a hitch.

If you share a screen snip of all the events to do with this key press issue, we can have a look and see where changes may be needed.

To take advantage of the diagonal directions you have to add other triggers after the ones already written:
If “Up” and “Right” are pressed > change KeyCommand set to “UpRight”
(and the other diagonal triggers)

The OP does not want diagonals. They want one key press to be registered, and only that one keypress to be actioned until it is released. Any other key is pressed during that time is ignored.

Sorry it took me so long to get back. Here’s what I have (I have three pics of it, it was bigger than I thought it would be)



Your “Any key is pressed” at the bottom of the 2nd screen shot is incorrect. If you look at my image, it’s inverted. It reads “If there are no keys being pressed”, whereas yours reads “If there are keys being pressed”.

Also, why you are creating a new image for each keypress? You can do this with animations. Have one sling object with an animation for each key press, direction or action. Give each animation a name for the keypress/action. It’ll make your events a whole lot cleaner and easier to work with.

I’ll give that a change.

Because I’m a dumb newbie who’s still learning :grin: I didn’t realize you could do that.

Alright, I’ll report back when I’ve made the changes and run it.

Corrected :stuck_out_tongue:

Post to this forum (or Discord) if you have questions about how to do it.

Aha! Making all of the animations for one object and then consolidating movements to those animations instead of four separate sprites made all the difference in working the bugs out!

Problem solved! Much obliged, friends!