我正在开发一个 android 应用程序(键盘驱动程序),首先我将蓝牙键盘与 android 设备连接,在我的 Inputmethod 服务中成功连接后,我正在接收按键并将其发送到当前打开的编辑器。问题是我无法弄清楚如何在 android 中打开/关闭大写锁定和 shift 键功能。
private BroadcastReceiver key3Receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int key = Integer.parseInt(intent
.getStringExtra(BluezService.COLONY_KEYPRESS_KEY));
int action = intent.getIntExtra(BluezService.EVENT_KEYPRESS_ACTION,
KeyEvent.ACTION_DOWN);
Log.d("++++ key recieved ", Integer.toString(key));
InputConnection ic = getCurrentInputConnection();
long eventTime = SystemClock.uptimeMillis();
if(key==2)
{
if(checkEnable==true){
ic.clearMetaKeyStates(KeyEvent.META_SHIFT_LEFT_ON);
Log.d("metakey", "turn off");
checkEnable=false;
return;
}else{
Log.d("metakey", "turn on");
checkEnable=true;
}
}
// ********* Hacks
if(key==8)
{
key=127;
}
if (key < 130) {
ic.sendKeyEvent(new KeyEvent(eventTime, eventTime, action,COLONYKEYCODE[key],
0, KeyEvent.META_SHIFT_ON, 0, 0, KeyEvent.FLAG_SOFT_KEYBOARD));
}
}
};