[android-developers] Re: how to inject non-english characters

2014-06-23 Thread Miha
Hi!

I'm also injecting keys, but I have developed a custom keyboard using 
/dev/uinput. I need to translate unicode keys to android key events and I'm 
using the getEvents method on KeyCharacterMap class like you guys. I'm also 
facing the same problem, that accented characters can not be inserted -- 
getEvents returns no events for such character arrays. Even if character 
array contains regular characters and then an accented character, nothing 
is returned.

Is there something wrong with how we're using getEvents or perhaps some 
other method that would return the required KeyEvents?

Regards,
 Miha

On Wednesday, September 19, 2012 9:17:01 AM UTC+2, Hardy Kahl wrote:

 Hi LeenuxGuy, 

 I found kind of a solution: 

 1. Backup clipboard content 
 2. Put your character in clipboard 
 3. Inject menu-key, then v-key. This is a keyboard shortcut for 
 pasting the clipboard. 
 4. Unfortunately Android is inserting spaces before and after the 
 content in some cases. 
 Try to remove them by injecting DPAD_LEFT, DELETE 
 5. Put the backed up clipboard content back in the clipboard. 

 That is in fact so ugly and unreliable, that I discarded it right away. 

 * On some phones the paste shortcut also triggers the menu. 
 * There is a racecondition in the clipboard. Sometimes the old 
 clipboard content is pasted instead of the just inserted character. 
 * I can't get rid of these spaces reliably. I don't know why Android 
 is doing this. That's even a pain when using the clipboard the 
 intended way. 

 So, currently I stick with english characters. Sorry. 

 I would be glad to hear from you, when you got a solution. 

 Best regards, 
 Hardy 



 2012/9/18 LeenuxGuy bijoy...@gmail.com javascript:: 
  Hi Hardy, 
  
  Did you ever find a solution for this?  I also have a signed app with 
  INJECT_EVENTS permissions, and I want to be able to send any character 
  (English or otherwise) on to various EditText fields, based on external 
  input. 
  
  
  
  On Tuesday, May 29, 2012 3:06:43 AM UTC-5, Hardy Kahl wrote: 
  
  I am programming on a remote control app. One of the tasks I am facing 
  is injecting characters. The code I am currently using looks like 
  this: 
  
  Instrumentation instr = new Instrumentation(); 
  
  String str=a; 
  
  // basically the same like calling instr.sendStringSync(str); 
  char[] chars = str.toCharArray(); 
  KeyCharacterMap keyCharacterMap = 
  KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); 
  KeyEvent[] keyEvents = m_KeyCharacterMap.getEvents(chars); 
  if (keyEvents != null) { 
  for (KeyEvent kev : keyEvents) { 
 instr.sendKeySync(kev); 
  } 
  } 
  
  That works perfectly on english characters (The characters show up in 
  EditText boxes). However, if I am trying to inject e.g. korean 
  characters, this fails. The function getEvents returns null, even when 
  I have configured korean language and keyboard. 
  
  I know there is another mehtod for injecting strings directly: 
  
  KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(), str, 0, 
 0); 
  instr.sendKeySync(event); 
  
  This is not working either - no characters shown in EditText boxes, 
  and onKeyMultiple() is not called either in my test activity. 
  
  This is strange since dispatchKeyEvent() with the same event works in 
  my test activity: 
  
  KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(), str, 0, 
 0); 
  dispatchKeyEvent(event); 
  
  I believe injecting the string directly is the correct way. However, 
  using instrumentation it looks like the event is discarded somewhere 
  in Android. 
  
  The reason why I am not using dispatchKeyEvent is that I have to 
  inject events no matter which activity is in front, even it is not my 
  own activity. I think that is not possible using dispatchKeyEvent, is 
  it? 
  Using Instrumentation this is possible. At least with english 
  characters. (My app is signed with the platform key and I've got the 
  permission INJECT_EVENTS). 
  
  How am I supposed to inject non-english characters? Any ideas? I ran 
  out of ideas :( 
  
  Best Regards, 
  Hardy Kahl 


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Android Developers group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[android-developers] Re: how to inject non-english characters

2012-09-19 Thread Hardy Kahl
Hi LeenuxGuy,

I found kind of a solution:

1. Backup clipboard content
2. Put your character in clipboard
3. Inject menu-key, then v-key. This is a keyboard shortcut for
pasting the clipboard.
4. Unfortunately Android is inserting spaces before and after the
content in some cases.
Try to remove them by injecting DPAD_LEFT, DELETE
5. Put the backed up clipboard content back in the clipboard.

That is in fact so ugly and unreliable, that I discarded it right away.

* On some phones the paste shortcut also triggers the menu.
* There is a racecondition in the clipboard. Sometimes the old
clipboard content is pasted instead of the just inserted character.
* I can't get rid of these spaces reliably. I don't know why Android
is doing this. That's even a pain when using the clipboard the
intended way.

So, currently I stick with english characters. Sorry.

I would be glad to hear from you, when you got a solution.

Best regards,
Hardy



2012/9/18 LeenuxGuy bijoy.an...@gmail.com:
 Hi Hardy,

 Did you ever find a solution for this?  I also have a signed app with
 INJECT_EVENTS permissions, and I want to be able to send any character
 (English or otherwise) on to various EditText fields, based on external
 input.



 On Tuesday, May 29, 2012 3:06:43 AM UTC-5, Hardy Kahl wrote:

 I am programming on a remote control app. One of the tasks I am facing
 is injecting characters. The code I am currently using looks like
 this:

 Instrumentation instr = new Instrumentation();

 String str=a;

 // basically the same like calling instr.sendStringSync(str);
 char[] chars = str.toCharArray();
 KeyCharacterMap keyCharacterMap =
 KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
 KeyEvent[] keyEvents = m_KeyCharacterMap.getEvents(chars);
 if (keyEvents != null) {
 for (KeyEvent kev : keyEvents) {
instr.sendKeySync(kev);
 }
 }

 That works perfectly on english characters (The characters show up in
 EditText boxes). However, if I am trying to inject e.g. korean
 characters, this fails. The function getEvents returns null, even when
 I have configured korean language and keyboard.

 I know there is another mehtod for injecting strings directly:

 KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(), str, 0, 0);
 instr.sendKeySync(event);

 This is not working either - no characters shown in EditText boxes,
 and onKeyMultiple() is not called either in my test activity.

 This is strange since dispatchKeyEvent() with the same event works in
 my test activity:

 KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(), str, 0, 0);
 dispatchKeyEvent(event);

 I believe injecting the string directly is the correct way. However,
 using instrumentation it looks like the event is discarded somewhere
 in Android.

 The reason why I am not using dispatchKeyEvent is that I have to
 inject events no matter which activity is in front, even it is not my
 own activity. I think that is not possible using dispatchKeyEvent, is
 it?
 Using Instrumentation this is possible. At least with english
 characters. (My app is signed with the platform key and I've got the
 permission INJECT_EVENTS).

 How am I supposed to inject non-english characters? Any ideas? I ran
 out of ideas :(

 Best Regards,
 Hardy Kahl

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: how to inject non-english characters

2012-09-19 Thread LeenuxGuy
Hi Hardy,

Did you ever find a solution for this?  I also have a signed app with 
INJECT_EVENTS permissions, and I want to be able to send any character 
(English or otherwise) on to various EditText fields, based on external 
input.



On Tuesday, May 29, 2012 3:06:43 AM UTC-5, Hardy Kahl wrote:

 I am programming on a remote control app. One of the tasks I am facing 
 is injecting characters. The code I am currently using looks like 
 this: 

 Instrumentation instr = new Instrumentation(); 

 String str=a; 

 // basically the same like calling instr.sendStringSync(str); 
 char[] chars = str.toCharArray(); 
 KeyCharacterMap keyCharacterMap = 
 KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); 
 KeyEvent[] keyEvents = m_KeyCharacterMap.getEvents(chars); 
 if (keyEvents != null) { 
 for (KeyEvent kev : keyEvents) { 
instr.sendKeySync(kev); 
 } 
 } 

 That works perfectly on english characters (The characters show up in 
 EditText boxes). However, if I am trying to inject e.g. korean 
 characters, this fails. The function getEvents returns null, even when 
 I have configured korean language and keyboard. 

 I know there is another mehtod for injecting strings directly: 

 KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(), str, 0, 0); 
 instr.sendKeySync(event); 

 This is not working either - no characters shown in EditText boxes, 
 and onKeyMultiple() is not called either in my test activity. 

 This is strange since dispatchKeyEvent() with the same event works in 
 my test activity: 

 KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(), str, 0, 0); 
 dispatchKeyEvent(event); 

 I believe injecting the string directly is the correct way. However, 
 using instrumentation it looks like the event is discarded somewhere 
 in Android. 

 The reason why I am not using dispatchKeyEvent is that I have to 
 inject events no matter which activity is in front, even it is not my 
 own activity. I think that is not possible using dispatchKeyEvent, is 
 it? 
 Using Instrumentation this is possible. At least with english 
 characters. (My app is signed with the platform key and I've got the 
 permission INJECT_EVENTS). 

 How am I supposed to inject non-english characters? Any ideas? I ran 
 out of ideas :( 

 Best Regards, 
 Hardy Kahl 


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en