Checking if any key is pressed

anyKeyPressed1

Recently I had needed a way to determine whether any key was pressed on the keyboard. This was because any key could potentially be used as an event trigger, and I didn’t want to assume anything about what those keys might be.

Without this check, the other safest way was to constantly execute the relevant methods, which may lead to reduced performance given a sufficient number of events on the map. Then I remembered there was a keyboard script available, which showed how to check the state of every key.

Using this idea, I could simply check if any of the keys were pressed, and set a flag as needed, and then provide that as a convenient script call.

Download

Script: download here

Installation

In the script editor, place this script below Materials and above Main

Usage

To check whether any key is being pressed, use the script call

Input.any_key_pressed?

Which will return true if any keys are being pressed, and false otherwise.

This may not work for input devices other than the keyboard.

40 Responses

  1. Rodman says:

    I’ll immediately clutch your rss feed as I can’t find your email subscription hyperlink or newsletter service.
    Do you have any? Please allow me realize in order
    that I could subscribe. Thanks.

  2. Kurtis says:

    If some one needs expert view regarding blogging then i advise him/her to visit this webpage, Keep
    up the good work.

  3. Xenia says:

    Have you ever thought about adding a little bit more
    than just your articles? I mean, what you say is important
    and everything. But just imagine if you added
    some great pictures or videos to give your posts more, “pop”!

    Your content is excellent but with images and videos, this site could undeniably be one of the
    most beneficial in its niche. Very good blog!

  4. Dangela says:

    Hey very nice blog!

  5. Rogers says:

    I always emailed this webpage post page to all my contacts, for the reason that
    if like to read it then my friends will too.

  6. Pernell says:

    Hi there it’s me, I am also visiting this site regularly, this website is really nice and
    the viewers are genuinely sharing good thoughts.

  7. Tashana says:

    Fabulous, what a blog it is! This web site gives
    valuable data to us, keep it up.

  8. Erendira says:

    Fantastic beat ! I would like to apprentice while you amend your
    website, how can i subscribe for a blog website? The account helped me a
    acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear idea

  9. Correna says:

    I’m curious to find out what blog system you’re utilizing?
    I’m having some small security problems with my latest website and I would like to find something more secure.
    Do you have any solutions?

  10. Noam says:

    You really make it appear really easy with your presentation however I find this topic to be really one thing that I feel I’d by
    no means understand. It seems too complicated and very extensive for me.
    I’m having a look forward for your subsequent publish, I will
    attempt to get the grasp of it!

  11. Canda says:

    After looking at a few of the articles on your website, I truly like
    your technique of writing a blog. I saved as a favorite it to my bookmark site list and will
    be checking back in the near future. Please visit my website as well and let me know how you feel.

  12. Feigy says:

    Have you ever considered writing an ebook or guest authoring on other websites?
    I have a blog based on the same information you discuss and would love to have you share some stories/information. I know my subscribers would appreciate your work.
    If you are even remotely interested, feel free to shoot me an e mail.

  13. Donnielle says:

    Hi there mates, how is all, and what you desire to say about this piece of writing, in my view
    its in fact awesome in favor of me.

  14. Kamika says:

    I do agree with all the ideas you have presented in your post.
    They are very convincing and will certainly work.
    Nonetheless, the posts are too brief for starters.
    Could you please prolong them a bit from next time?

    Thank you for the post.

  15. Charlette says:

    WOW just what I was looking for. Came here by searching for website

  16. Junius says:

    Remarkable! Its really awesome article, I have got much clear idea on the topic of from this piece of writing.

  17. Tracee says:

    Today, I went to the beach front with my kids. I found a sea shell and gave it to my 4 year old daughter and said
    “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.

    There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is completely off topic
    but I had to tell someone!

  18. Brittanni says:

    Hi there colleagues, fastidious paragraph and good arguments commented here, I am really enjoying by these.

  19. Tamila says:

    I loved as much as you’ll receive carried out right here.
    The sketch is tasteful, your authored material stylish.
    nonetheless, you command get got an nervousness over that you wish be delivering the following.
    unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case you shield this hike.

  20. Tatiana says:

    I go to see each day a few sites and sites to read articles or reviews, but this website
    offers feature based articles.

  21. Densie says:

    Quality posts is the key to interest the viewers
    to pay a visit the web site, that’s what this website is providing.

  22. Jedadiah says:

    If you wish for to grow your know-how only keep visiting
    this web page and be updated with the newest news update posted here.

  23. Gretel says:

    Hi, i read your blog from time to time and i own a similar
    one and i was just wondering if you get a lot
    of spam feedback? If so how do you stop it, any plugin or anything you
    can recommend? I get so much lately it’s driving
    me crazy so any assistance is very much appreciated.

  24. Selah says:

    hi!,I really like your writing very a lot! proportion we be in contact more about your
    post on AOL? I need a specialist in this space to resolve my problem.
    May be that is you! Having a look ahead to peer you.

  25. Melita says:

    Excellent blog here! Also your web site loads up
    very fast! What web host are you using? Can I get your affiliate link to your host?
    I wish my website loaded up as fast as yours lol

  26. Jacobe says:

    Spot on with this write-up, I truly feel this amazing site needs a great deal
    more attention. I’ll probably be returning to read through more, thanks for the information!

  27. Jannell says:

    What’s up colleagues, its enormous article concerning educationand completely defined,
    keep it up all the time.

  28. Lashanta says:

    An outstanding share! I’ve just forwarded this onto a friend who had been conducting a little
    homework on this. And he in fact ordered me breakfast because I stumbled upon it for
    him… lol. So allow me to reword this…. Thank YOU for the meal!!
    But yeah, thanks for spending time to discuss this issue here on your blog.

  29. Janiqua says:

    Incredible quest there. What happened after? Good luck!

  30. Nou says:

    Hi, after reading this remarkable post i am as well cheerful to share
    my experience here with mates.

  31. Karrina says:

    I’m impressed, I have to admit. Rarely do I come across a blog that’s both educative and
    interesting, and let me tell you, you’ve hit the nail on the head.
    The problem is something which not enough men and women are speaking
    intelligently about. Now i’m very happy I came across this during my search for
    something concerning this.

  32. Brighid says:

    Hey there! This post could not be written any better!
    Reading through this post reminds me of my old room mate!
    He always kept chatting about this. I will forward this article to him.
    Fairly certain he will have a good read. Many thanks for sharing!

  33. Shenise says:

    It’s very trouble-free to find out any topic on web as compared
    to books, as I found this paragraph at this web site.

  34. Korrin says:

    Very soon this web page will be famous amid all blogging and site-building
    viewers, due to it’s pleasant content

  35. Katarzyna says:

    Admiring the persistence you put into your site and
    detailed information you provide. It’s great to come across a
    blog every once in a while that isn’t the same unwanted rehashed information. Excellent read!
    I’ve bookmarked your site and I’m adding your RSS feeds to my Google account.

  36. Backoffson says:

    Im probably dumb, but how exactly do I use this? Im making an event that will return to main menu when you press anykey, I put “Return to title screen” under “Input.any_key_pressed?” I imagine thats not how it works cus it didnt work for me, it just automatically returned to the menu. Again im probably just dumb but some help would be greatly appreciated!

  37. Zephadus says:

    I’ve recently discovered that this snippet conflicts with your Event Trigger Labels script.
    Any idea why that might be? It throws an error: “SystemStackError occurred. Stack level too deep.”

Leave a Reply

Your email address will not be published. Required fields are marked *