I have tried to send keyevent from EditText
. For this I was using InputConnectionWrapper
which I had taken from method onCreateInputConnection()
:
ZanyInputConnection zic;
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
zic = new ZanyInputConnection(super.onCreateInputConnection(outAttrs),
true);
return zic;
}
Inside ZanyInputConnection
I wrote method which turn on shift:
private class ZanyInputConnection extends InputConnectionWrapper {
public ZanyInputConnection(InputConnection target, boolean mutable) {
super(target, mutable);
}
public void turnOnShift(){
long eventTime = SystemClock.uptimeMillis();
sendKeyEvent(new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE));
sendKeyEvent(new KeyEvent(eventTime, SystemClock.uptimeMillis(),
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE));
}
}
It called inside onSelectionChange()
method:
@Override
public void onSelectionChanged(int selStart, int selEnd) {
zic.turnOnShoft();
}
But when method called nothing happens.
0 comments:
Post a Comment