Checking if any key is pressed

● ARCHIVED · READ-ONLY
Started by Tsukihime 3 posts View original ↗



  1. 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.


    Get the script at HimeWorks!
  2. Strange, I'm getting an "end of medium" character (0x19) on windows 8 that is always being pressed. Could be something on my machine.


    Didn't occur on vista. Wonder if anyone else has this problem.


    It's not a character that you can actually type unlike the tab key (0x09), so I could probably just safely filter it out.
  3. Tsukihime said:
    Wonder if anyone else has this problem.
    Unfortunately, I have that problem. :(
    I checked which one was the culprit and it returned the last key (the 255th) with a state of -128, so I removed it from the 'Keys_To_Check' array, and finally it worked how it should.


    I just want to know, what exactly is the 255th button in that array? Will I get any unexpected check results if I remove that button?


    I have checked multiple keyboard scripts, but none of them seems to include that one. >.>


    I have win XP and I use a very old IBM laptop if that matters.


    EDIT:


    After some testing, it seems that there is no way to differentiate between a button trigger and a button press/repeat, so if the player keeps the button pressed even for a very short time frame (like 2-3 frames), the check will return true.


    Is there any way I could eliminate button press and button repeat from the check and leave only the button trigger to check for? *-*