2

I'm trying to do this with jQuery and the three keyup, keydown and keypress events, and i implemented my custom ctrl+a and ctrl+c functions but there must be another way for converting a latin character into a cyrillic one. I want it to be seamless, so when the user types in a latin character, he won't even see it, he will see the cyrillic one straight away, and also if he pastes some text into the field the text should be converted too...

Anyone has some good ideas about how should i implement this? I already have a library which can return a cyrillic letter from a latin keypress code so i just need to find a good way to implement it without blocking all the other keyboard functions...

Thanks

Kitze
  • 709
  • 3
  • 8
  • 21

1 Answers1

0

I guess it's time to find out how cursor position is being found and set. (you might skip that until if characters are only to be appended at the end of value)

If you know this, you can easily find where the letter was pressed, change the value and move the cursor. And of course, cancel the event so that latin character is not pressed. This answer might be useful regarding the character filtering.

Here's a simple fiddle that reverts all characters (z=a). It uses onkeydown. Text cursor magic is not implemented.

Community
  • 1
  • 1
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • I'm already doing this, but mobile devices don't fire keyup and keydown events, just keypress, so it makes things a little bit more complicated. – Kitze Jan 21 '14 at 12:51
  • Quite more complicated then. I can't figure out how to deal with this without some nasty timeouts, which is a thing you don't want to do. But you should really point this problem out in your question - it makes everything way more complicated. – Tomáš Zato Jan 21 '14 at 13:11
  • I implemented cursor magic, i even test if you have something selected it will first delete it and then it will start typing. But now i opened it on mobile and nothing works because of the keydown and keyup events, dammit. – Kitze Jan 21 '14 at 13:25
  • I can't do more than upvote your answer, which I already did. I'm curious if any smart solution will appear. – Tomáš Zato Jan 21 '14 at 13:31