3

I need to paste the Arabic text into the input field, I can handle it for mac as there is

if (((Input.GetKey(KeyCode.RightCommand) || Input.GetKey(KeyCode.LeftCommand))
&& Input.GetKeyDown(KeyCode.V)) || Input.GetMouseButtonUp(1))
{
    inputField.text = ArabicHelper.faConvert(ClipboardHelper.Clipboard);
}

I placed this code in the update method and copied text will be in ClipboardHelper. ClipboardBut how can I recognize that user is pasting some content in iOS or Android is there any events or keys to recognizing that pasting.

Programmer
  • 121,791
  • 22
  • 236
  • 328
sahithi
  • 1,039
  • 2
  • 14
  • 37
  • @AustinWBryan, Thanks for responding but how should I change my code, Please suggest me the way to recognize pasting in ios and Android. – sahithi Jul 23 '18 at 08:23
  • Arent there any detection keys for pasting in devices in unity? – sahithi Jul 23 '18 at 11:07
  • No. You have to implement that yourself. – Programmer Jul 23 '18 at 11:12
  • Could you please suggest me any samples on that I have been searching but finding nothing, It would be a great help to me. – sahithi Jul 23 '18 at 11:18
  • Check back in about 40 minutes. I don't think it's a good idea to do this with `Input.GetKey(KeyCode.RightCommand)` even on Desktop devices. I haven't done anything like this before but I will see if I can come up with something. – Programmer Jul 23 '18 at 11:21
  • Thank you so much, looking really forward for help – sahithi Jul 23 '18 at 11:24
  • try this https://stackoverflow.com/a/14981376/7505436 – vm345 Jul 23 '18 at 11:36
  • 1
    @vm345 This is Unity and is done with C#. It also has to work with iOS and Android not just Android – Programmer Jul 23 '18 at 11:38
  • Yes exactly as Programmer said @vm345, I need that should be work for iOS and Android, Thanks anyway for help. – sahithi Jul 23 '18 at 11:58
  • I got something. Will test on Android to make sure it works there before posting. If it works on Android then it should on iOS. You will have to do the iOS test yourself. What's your Unity version? – Programmer Jul 23 '18 at 12:14
  • Sorry for late response @Programmer,this is unity im using 2018.1.0f2 – sahithi Jul 23 '18 at 12:35
  • The proper solution is with `InputField.onValidateInput` but there is a bug with it on Android. It get's called more than it should on Android. The solution I have would have worked on Android but because of this bug, it won't. I don't know if this bug also exist on iOS. Anyways, sorry I can't help at this moment. [Here](https://answers.unity.com/questions/1520866/inputfields-onvalidateinput-bug.html) one question about this bug on Android – Programmer Jul 23 '18 at 14:03
  • Thank you for help @Programmer, I will go through that. – sahithi Jul 23 '18 at 14:10

2 Answers2

0

You could keep the current inputted text length in a private variable. Then, once value is changed in the InputField (see the docs), get the new length, compare to the old one and if the length difference is more or equal to 2, player has pasted something. It is impossible to input two characters in single key press.

tsvedas
  • 1,049
  • 7
  • 18
  • Thank you @Tomas Svedas.I will try this way – sahithi Jul 23 '18 at 13:29
  • I thought about this but how about 1 character paste? You think someone will never paste one character? – Programmer Jul 23 '18 at 13:51
  • Good point, @Programmer. Though, most people will probably just type the single character instead of pasting it. – tsvedas Jul 23 '18 at 14:33
  • Yes but the most useful case of copying just one char is when you want to copy a char from another language or just a symbol. I do most of them time and it saves time of looking them up or having to change the language of my platform just to get that char from a keyboard. – Programmer Jul 23 '18 at 14:38
  • What about checking pressed key code, converting it to string and then comparing it with the entered one? If they match - it was typed, if not - it was pasted. – tsvedas Jul 23 '18 at 14:44
0

https://docs.unity3d.com/Manual/script-InputField.html

I would use the On Value Change to call your format method on the InputField every time the user change the text (even when the user just type, not copy&paste).

Just like Tomas Švedas only without check the length.

LiefLayer
  • 977
  • 1
  • 12
  • 29