Comunidad de diseño web y desarrollo en internet online

Borrar acentos al escribir en un TextField

Citar            
MensajeEscrito el 01 Jul 2009 03:29 pm
Hola a todos,
estoy haciendo un pequeño programa para practicar mecanografía con AIR, en el que uso un TextField para ir escribiendo el texto y me he encontrado con un problema a la hora de borrar los acentos.
Por ejemplo, si pulsas en este orden las teclas:
"r", "acento", "borrar", "o"

un editor de texto cualquiera mostraría "ro"
pero en un TextField la salida es "´o"

es decir, que al pulsar la tecla de borrar primero me borra el caracter y luego me escribe el acento, cuando lo que debería hacer es simplemente desactivar el acento.
¿hay alguna forma de cambiar esto?
También he pensado en usar un EventListener en el TextField para capturar las pulsaciones del teclado, y en caso de que se pulse la tecla de borrar que compruebe si hay algún acento activado, pero ¿hay alguna forma de detectar si el acento está activado o no en AS3?

Gracias.

Por isidoro

Claber

498 de clabLevel

2 tutoriales

Genero:Masculino  

firefox
Citar            
MensajeEscrito el 01 Jul 2009 04:21 pm
Probando con el Notepad (que considero un editor de texto cualquiera) me sale

r->acento->del->o


Ten en cuenta que las combinaciones de tecla se ven afectadas por el lenguaje del OS, el OS mismo, etc ....

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 01 Jul 2009 04:31 pm
:)Tienes razón, con el Wordpad también pasa lo mismo (yo sólo lo había probado con Word y el Block de notas). Pero sigo necesitando que al pulsar "del" se desactive el acento cuando esté activado.

Por isidoro

Claber

498 de clabLevel

2 tutoriales

Genero:Masculino  

firefox
Citar            
MensajeEscrito el 02 Jul 2009 10:02 am
Bueno, después de algunas pruebas he conseguido hacer un pequeño apaño para que funcione. Aquí pongo un ejemplo:

Código ActionScript :

var tf:TextField = new TextField();
tf.x = 40;
tf.y = 40;
tf.width = stage.stageWidth - 2 * tf.x;
tf.height = stage.stageHeight - 2 * tf.y;
tf.multiline = true;
tf.wordWrap = true;
tf.border = true;
tf.type = TextFieldType.INPUT;
tf.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
tf.addEventListener(Event.CHANGE, changeHandler);
addChild(tf);


var delPressed:Boolean;
var lastChar:String;
var auxChar:String;

function keyDownHandler(e:KeyboardEvent):void
{
   e.updateAfterEvent();
   delPressed = (e.keyCode == Keyboard.BACKSPACE) ? true : false;
   lastChar = tf.text.slice(-1);
}

function changeHandler(e:Event):void
{
   if (delPressed)
   {
      auxChar = tf.text.slice(-1);
      if ((auxChar == "´") || (auxChar == "`") || (auxChar == "¨"))
      {
         tf.text = tf.text.slice(0, -1) + lastChar;
      }
   }
}

Por isidoro

Claber

498 de clabLevel

2 tutoriales

Genero:Masculino  

firefox
Citar            
MensajeEscrito el 28 Dic 2009 10:13 pm
/* First of all thank you for share your code.
This is to correct when you want to write these caracters ´,`,¨, ~, and then use BACKSPACE.
if you write something like: ( ´this`. ) when you press backspace after the dot, the text look like ( ´this. ) when the correct should be ( ´this` ). This is what I tried to fix with this change because when you press Backspace more than
one time is becase you are not trying to write but delete.
*/

var tf:TextField = new TextField();
tf.x = 40;
tf.y = 40;
tf.width = stage.stageWidth - 2 * tf.x;
tf.height = stage.stageHeight - 2 * tf.y; tf.multiline = true;
tf.wordWrap = true;
tf.border = true;
tf.type = TextFieldType.INPUT;
tf.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
tf.addEventListener(Event.CHANGE, changeHandler); addChild(tf);

var delPressed:Boolean = false;

var delPressmore:Boolean = false; //if BACKSPACE is pressed more than one time in sequence

var lastChar:String;
var auxChar:String;

function keyDownHandler(e:KeyboardEvent):void {
e.updateAfterEvent();

// if BACKSPACE was pressed once and it is pressed again delPressmore will be true
delPressmore = (delPressed && (e.keyCode == Keyboard.BACKSPACE)) ? true : false;

delPressed = (e.keyCode == Keyboard.BACKSPACE) ? true : false;
lastChar = tf.text.slice(-1);
}

function changeHandler(e:Event):void {
if (delPressed) {
auxChar = tf.text.slice(-1);
if (((auxChar == "´") || (auxChar == "`") || (auxChar == "¨") || (auxChar == "~")) && !delPressmore) { // and is the first time that BACKSPACE is pressed
tf.text = tf.text.slice(0, -1) + lastChar;
}
}
}

Por gfontes

1 de clabLevel



 

msie7
Citar            
MensajeEscrito el 28 Dic 2009 10:27 pm
Gracias gfontes por copypastear el code 6 meses después de que el hilo fue resuelto, intenta la próxima traducir la parte de inglés, así aunque llegues muy tarde, agregas valor

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 29 Dic 2009 12:02 am
Jorge
Lo siento por el Inglés, porque no hablo español, hablo portugués. Seguramente esto no volverá a suceder.

La traducción para que el Inglés es:
/ * En primer lugar muchas gracias por compartir su código.
Esto es correcto cuando se desea escribir estas',`,¨, carácteres ~, y luego usar RETROCESO.
Si escribes algo como: ( ´esto`. ) cuando se pulse la tecla de retroceso después del punto, el aspecto de texto como ( 'esto. ) cuando el correcto debería ser ( ´esto` ). Esto es lo que traté de arreglar con este cambio porque cuando se presiona Retroceso de más de una vez es porque no están tratando de escribir, sino eliminar.
* /

Espero que no tiene un montón de errores, porque he utilizado el traductor de Google.

Por gfontes

1 de clabLevel



 

msie7
Citar            
MensajeEscrito el 29 Dic 2009 12:11 am
xD Pues de hecho gfontes tiene razón, el código que puse hace meses falla y lo cambié por el siguiente, pero no lo posteé.
[Thanks gfontes, some time ago I realized my mistake and changed it with this code]

Código ActionScript :

var tf:TextField = new TextField();
tf.x = 40;
tf.y = 40;
tf.width = stage.stageWidth - 2 * tf.x;
tf.height = stage.stageHeight - 2 * tf.y;
tf.multiline = true;
tf.wordWrap = true;
tf.border = true;
tf.type = TextFieldType.INPUT;
tf.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
tf.addEventListener(TextEvent.TEXT_INPUT, textInputHandler);
addChild(tf);

var delPressed:Boolean;
var lastChar:String;

function keyDownHandler(event:KeyboardEvent):void
{
   event.updateAfterEvent();
   delPressed = (event.keyCode == Keyboard.BACKSPACE);
   if (delPressed) lastChar = event.target.text.slice(-1);
}

function textInputHandler(event:TextEvent):void
{
   if (!delPressed) return;
   event.preventDefault();
   event.target.appendText(lastChar);
   event.target.setSelection(event.target.length, event.target.length);
}

Por isidoro

Claber

498 de clabLevel

2 tutoriales

Genero:Masculino  

firefox
Citar            
MensajeEscrito el 29 Dic 2009 12:55 am
Gracias Isidoro,
siga compartiendo sus conocimientos.
Dios los bendiga

Por gfontes

1 de clabLevel



 

msie7

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.