开启/关闭大写锁定,并转变对机器人编程键 [英] Turn on/off caps lock and shift key programatically on android

查看:135
本文介绍了开启/关闭大写锁定,并转变对机器人编程键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序(键盘驱动程序),其中第一个我连接蓝牙键盘与Android设备,我收到了关键presses并将其发送给当前打开的编辑器,在我的Inputmethod服务连接成功后。问题是,我无法弄清楚如何打开/关闭大写锁定,并在Android的shift键的功能。

任何帮助!

这是广播接收器,它是由蓝牙键盘

接收键

 私人的BroadcastReceiver key3Receiver =新的BroadcastReceiver(){

    @覆盖
    公共无效的onReceive(上下文的背景下,意图意图){
        INT键=的Integer.parseInt(意向
                .getStringExtra(BluezService.COLONY_KEY preSS_KEY));
        INT行动= intent.getIntExtra(BluezService.EVENT_KEY preSS_ACTION,
                KeyEvent.ACTION_DOWN);
        Log.d(++++键:收到,Integer.toString(键));

        InputConnection集成电路= getCurrentInputConnection();
        长eventTime = SystemClock.uptimeMillis();

        // *********黑客
        如果(关键== 8)
        {
            键= 127;
        }


        如果(钥匙< 130){
            ic.sendKeyEvent(新的KeyEvent(eventTime,eventTime,动作,COLONYKEY code [关键]
                    0,COLONYKEY code [关键],0,0,KeyEvent.FLAG_SOFT_KEYBOARD));
        }

    }
};
 

解决方案

在您的EditText(或酌情)使用属性:

 安卓inputType =textCapCharacters
 

在默认情况下充分利用所有的字母。阅读 inputType 了解它的其他功能。

I am developing an android application (keyboard driver) in which first I am connecting Bluetooth keyboard with android device , after successful connection in my Inputmethod service I am receiving key presses and send it to currently open editor. The problem is that I am unable to figure out how to turn on/off caps lock and shift key functionality in android.

Any help !!

This is the broadcast receiver which is receiving keys from Bluetooth keyboard

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();

        // ********* Hacks
        if(key==8)
        {
            key=127;
        }


        if (key < 130) {                
            ic.sendKeyEvent(new KeyEvent(eventTime, eventTime, action,COLONYKEYCODE[key],
                    0, COLONYKEYCODE[key], 0, 0, KeyEvent.FLAG_SOFT_KEYBOARD));
        }

    }
};

解决方案

In your EditText (or wherever appropriate) use the attribute:

android:inputType="textCapCharacters"

to capitalize all letters by default. Read inputType for its other features.

这篇关于开启/关闭大写锁定,并转变对机器人编程键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆