Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Best way to see if any key is pressed?

Dko

Member

I was just wondering how I would test if any key was being pushed? I know I probably could make a ton of Input.press?() calls but there probably is a better way. Well thanks for any help :3
 

Rare

Member

Try this...

Make a new common event (database), call it "X Button Pushed" or whatever.

Set the common event trigger to parallel process and make the condition switch called "X button pushed" or whatever.

Then, under that common event make a conditional branch and go to the 4th page under the conditional branch box and look for "Button is pressed".

Set that to whatever button you want (NOTE! The letters in the box ARE NOT the same on the keyboard. For example, "x button" would not be "x" on your keyboard. For a full list of the RMXP buttons to the keyboard buttons search the site...) and click ok.

Then, make whatever you want to happen under the conditional and complete the common event.

Now...whenever you want the common event to be on...just make an event that turns the condition switch on.

Hope that helps!
 

Dko

Member

Sorry but thats not what I meant. >.< I'm trying to code something where I have to know if 'any' of these rpg maker keys is pressed. Not just a single specific key and using scripts.
 
Any key???

Or are you testing for a specific key (like Q, T, W, or J)?

Alework's Input Module combined with Alework's Keyboard Module will work rather well for checking the whole keyboard. And the Aleworks Keyboard Add-On allows you retrieve what 'key' is pressed rather than actually testing if a key WAS pressed (getting a true/false value).
 
You can use something like Near Fantastica's Keyboard Input Module to check on a key... or set of keys.

Normally, you would add something like:
Code:
if Input.get_letters    == "A"
to detect the keypress of the actual 'A' on your keyboard, but it also returns 'nil' if the button isn't pressed.

So you could use this:
Code:
if Input.get_letters    != nil
This would check to see if ANY letter key was pressed.

This specific code doesn't check buttons like Space, Enter, Escape, Ctrl and etc.... but there are other calls in that system for those keys too...
 
Your best bet would be to do something like this:
Code:
a_pressed = Input.press?(Input::A)
b_pressed = Input.press?(Input::B)
# ...

if a_pressed && b_pressed # && ...
  # your code
# ...

Don't be afraid to assign local variables to true or false, based off whether a key is pressed like above. Then, use a single if statement with different booleans to get what you want.

And if I confused you, tell me what you are exactly wanting.

You could always of course create your own methods in the Input module.

Code:
module Input
  def self.any_button_pressed?
    for c in [A, B, C, X, Y, Z, L, R, ALT, SHIFT, CTRL]
      return true if self.press?(c)
    end
    return false
  end
end
 
But if he is only using keys in RMXP, couldn't he use the command for that in the Event menu?
To me, your small bits of script look like they would deal with any key on the keyboard.

I think you need to elaborate, Dko.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top