您可能无法像这样“禁用粘贴”(如果您自己不以某种方式托管 Flash 控件,例如,在 Windows 应用程序或某种浏览器扩展中),但您当然可以对方式做出很好的猜测有人正在使用基于计时器的数学应用程序。这是一个 Flex 应用程序的(超级)粗略示例,说明了我的意思:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*" creationComplete="this_creationComplete(event)">
<mx:Script>
<![CDATA[
private var timer:Timer;
import flash.events.Event;
private function this_creationComplete(event:Event):void
{
timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, timer_tick);
timer.start();
}
private function timer_tick(event:TimerEvent):void
{
var elapsedTimeInMinutes:Number = timer.currentCount / 60;
var averageWordLength:Number = 4;
var humanlyPossible:Number = 200;
var thisPersonsSpeed:Number = (txtTest.text.length / averageWordLength) / elapsedTimeInMinutes;
if (thisPersonsSpeed > humanlyPossible)
{
txtSpeed.text = "Wait, " + Math.floor(thisPersonsSpeed).toString() + " words per minute? This clown is probably cheating.";
txtTest.enabled = false;
timer.stop();
}
else
{
txtSpeed.text = "Currently typing " + Math.floor(thisPersonsSpeed).toString() + " wpm. Hurry up! Faster!";
}
}
]]>
</mx:Script>
<mx:VBox>
<mx:TextArea id="txtTest" width="600" height="300" />
<mx:Text id="txtSpeed" />
</mx:VBox>
</mx:Application>
本质上,它只是一个计算每分钟字数的计时器;如果该数字超过某个阈值,则计时器停止,并且表单禁用。
当然,它不是铁板钉钉的,如果我自己实现它,我会加入一些额外的面向时间的保护措施(例如,在不活动期间停止计时器等),但它应该说明这一点。我敢肯定还有其他解决方案,但是像这样简单的事情可能对您来说已经足够了。
更新:有几个人提到了 Event.PASTE,它可以工作,但在 ActionScript 2 / Flash Player 9 中不存在。如果您能够确保 Flash Player 10 并且可以在 ActionScript 3 中编写脚本,那就另当别论了选项。