简体   繁体   English

如何禁用空格键并在网页上输入密钥?

[英]How do I disable use of the space bar and enter keys on my webpage?

I'm making a site where a user repeatedly clicks a button to increase his/her score. 我正在建立一个用户反复单击按钮以增加其得分的网站。 Apart from using clicking bots, people can also click the button, and then without letting go of the mouse, hold down the enter or space bar key to get clicks at ridiculous speed, and can just place an object on one of these keys to hold it down all night etc. 人们除了可以使用单击机器人以外,还可以单击按钮,然后在不松开鼠标的情况下,按住Enter键或空格键以惊人的速度单击,并且可以将对象放置在其中一个键上以保持一整夜下来等等

Is there any way to stop this? 有什么办法可以阻止这种情况?

I tried adding a javascript script that disables the enter key, but it didn't work. 我尝试添加禁用ENTER键的JavaScript脚本,但是没有用。 Is there any other way to do it? 还有其他方法吗?

Thanks 谢谢

Maybe have a look at jKey . 也许看看jKey It is a jQuery plugin to allow key shortcuts, but you will maybe be able to do what you want with it. 它是一个jQuery插件,允许使用快捷键,但是您也许可以使用它来做您想做的事情。

您可以测量两次连续点击之间的时间,如果间隔少于100毫秒,则忽略该点击。

could you not set a flag when the button is clicked, then start a timer? 单击按钮然后启动计时器时,是否可以不设置标志? When the timer expires unset the flag again. 当计时器到期时,再次取消设置该标志。

When the button is clicked check if the flag is set, if it is do not increase the score. 单击按钮时,检查是否设置了标志,如果没有设置,则不增加分数。 you could also reset the timer to stop people just increasing their score as soon as the timer goes off. 您还可以重置计时器,以在计时器关闭后立即停止仅增加分数的人员。

My jQuery is not all that so I can't give an example off the top of my head. 我的jQuery并不是全部,所以我无法举一个例子。

This would have the advantage that it should work against bots as well, although the bot could just be programmed to click as soon as the flag expired... 这样做的好处是,它也应该与机器人对立,尽管可以将机器人编程为在标志过期后立即单击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM