- Home /
Can keyboard repeat rate be detected?
I've got a game I use in research. As people learn that a light predicts an attacking spaceship, they start hitting a key associated with a weapon to charge it up before the ship appears. I'm using input.getkeydown to detect keystrokes. Typically I get response rates around 4-5 presses per second when they're prepping the weapon. But, today I got someone with rates up to 60 (framerate). I assume the person has their keyboard repeat rate and delay set to some values such that on each frame Unity thinks the key had been released and re-pressed and he/she is simply holding the key down. Is their any way I can detect those settings ahead of time?
Answer by Bunny83 · Nov 24, 2021 at 11:11 AM
This has nothing to do with repeat rates since they are irrelevant for GetKeyDown. Those events only fire when a key is pressed down. The actual repeat rate of the keyboard / OS is only relevant for character input events in the UI / GUI system.
If you see 60 keydown events per second, the user most likely uses something like AutoHotKey or a keyboard that can simulate keypresses at those rates (usually even higher rates).
No, you can't really detect that as it doesn't need to be related to anything on the machine your game is running on. It could be an external hardware (like one of those programmable macro keyboads G15 G19, ...)
What you can do is restrict the max rate at which the user can actually execute that action by using a timer. Of course you have to pick a reasonable limit. Something like 15 clicks per second is probably a good limit. Barely anyone in the world is getting above 10 CPS. Though most games simply have some sort of penalty system when you click way too early or way too often. So if each click generates a score based on how far off they are from the correct moment, all those excess clicks would have a huge negative impact on the score.
Since this is for a research project I would simply hard limit the click rate as I said before. In other words if the delay between two clicks is smaller than a certain threshold for a couple of clicks, void the result. If this is actually part of a study, if you detect a cheater, I would actually reject this account completely because he would most likely try other means to cheat. Of course the detection has to be 99.9% certain. If this is for research studies there's no need to notify the user that he has been caught cheating. Just flag his results internally so you would not include them in the analysis.
Though we have no idea what this is actually about or what the users are actually supposed to do. If the goal is to spam the button as fast as they can, using a hard limit of 15 is probably the best solution. If more than 10 clicks in total are below that threshold or more than 4 consecutive clicks are below that threshold I would flag the results as invalid.
Thanks for that- I'll just chuck the ones I get that are clearly impossible & replace them. This is the first one I've got out of about 400 people.
Your answer
Follow this Question
Related Questions
KeyCode to Ui ? for mobile 1 Answer
Sometimes my character's controls doesn't respond (lag?) 1 Answer
How to Play Sound on Button Highlight 2 Answers
Unity app losses focus when Android keyboard is active through InputField 2 Answers
how to hide ios keyboard but keep input field in focus for Voice Control 0 Answers