Checking if any key is pressed

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English



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!
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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.
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
822
First Language
Hungarian
Primarily Uses
RMVXA
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? *-*
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,868
Messages
1,017,066
Members
137,576
Latest member
SadaSoda
Top