devxlogo

Detecting Multiple Simultaneous Keypresses

Detecting Multiple Simultaneous Keypresses

Question:
I need to know if you can have more than one keydown at a time because itwon’t let me turn and fire at the same time. Using the keydown event howdo you tell when there is two or more keys down other than the shift, ctrl,and alt keys? like how can you tell when “A and B” are pressed.

Answer:
Unfortunately, the only keys that can modify other keys are the Shift,Ctrl, and Alt keys. If you press a letter or number key down with anotheryou will get two KeyPress events. The best suggestion I can offer is tochange your fire button to be the Ctrl key and your forward motion be theShift key. You can detect when Ctrl and Shift are down together, or eventhe Alt key with them. Either way, you can only use those keys togetherwith one alphanumeric character

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist