Hi all. In my application, I want to check the username and password input. I hope the app only accept the human keyboard typing input for the username and password, and refuse the copy-paste input.
What is the approach for this? Any suggestion is appreciated. Thank you.
<mx:TextInput id="txtIp" change="txtChangeHandler(event)"/>
<mx:Script>
<![CDATA[
private var controlFlag:Boolean = false;
private function init():void{
this.addEventListener(KeyboardEvent.KEY_DOWN,kbdHandler);
this.addEventListener(KeyboardEvent.KEY_UP,kbuHandler);
}
private function kbdHandler(event:KeyboardEvent):void{
if(event.keyCode==Keyboard.CONTROL){
controlFlag = true;
}
if(controlFlag && event.keyCode==Keyboard.V){
event.preventDefault();
}
}
private function kbuHandler(event:KeyboardEvent):void{
if(event.keyCode==Keyboard.CONTROL){
controlFlag = false;
}
}
private function txtChangeHandler(event:Event):void{
//
}
]]>
</mx:Script>
Try with this logic.. Let me know if it helps
hi, you can get more detail of keyboard control from "Programming ActionScript 3.0", the docment from Adobe
http://livedocs.adobe.com/flex/3/html/help.html?content=Part6_ProgAS_1 .html
look at chapter 22 - "Capturing user input" there are some codes to check user key typing.
I am not able to prevent copy-paste, but from keycode, we know copy-paste use CTRL and v key.
North America
Europe, Middle East and Africa
Asia Pacific
Copyright © 2012 Adobe Systems Incorporated. All rights reserved.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).