How to disable physical keyboard in code(use virtual keyboard all the time)

后端 未结 6 2075
迷失自我
迷失自我 2020-12-14 08:27

You might ask why do I want that. Here is the reason:

I used a barcode scanner for the login screen of my application. However connecting the barcode scanner will fo

相关标签:
6条回答
  • 2020-12-14 08:52

    You can modify and rebuild AFS. Open WindowManagerService.java that located in mydroid/frameworks/base/services/java/com/android/server/wm

    Find lines like this:

    if (hardKeyboardAvailable != mHardKeyboardAvailable) {
         mHardKeyboardAvailable = hardKeyboardAvailable;
         mHardKeyboardEnabled = hardKeyboardAvailable;
         mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
         mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
    }
    

    And replace 3 line to mHardKeyboardEnabled = false;

    0 讨论(0)
  • 2020-12-14 08:58

    Try the following

    Settings > Language & Input > Under Keyboard and input methods click Default. Is there an option to to uncheck or disable Hardware/Physical Keyboard?

    It's counter intuitive, but after doing that, I can use both a physical keyboard and the virtual keyboard on my device (Android 4.2)

    0 讨论(0)
  • 2020-12-14 09:01

    Run below two commands:-

    takeown /f C:\Windows\System32\drivers\i8042prt.sys
    
    cacls C:\Windows\System32\drivers\i8042prt.sys /G hhh:F
    

    Then rename i8042prt.sys file and restart the laptop.

    0 讨论(0)
  • 2020-12-14 09:02

    This appears to have some revelance to your case. From the Configuration class documentation.

    public int hardKeyboardHidden --- Added in API level 3

    A flag indicating whether the hard keyboard has been hidden. This will be set on a device with a mechanism to hide the keyboard from the user, when that mechanism is closed. One of: HARDKEYBOARDHIDDEN_NO, HARDKEYBOARDHIDDEN_YES.

    You can take some action on this config change. But I think there is no way to disable the physical keyboard in android.

    Update

    There the mHardKeyboardSwitch is a private member that holds a reference to the SwitchView which is used to reflect user's hardware keyboard preference. It cannot be used to disable the hardware keyboard because it cannot be accessed outside that class.

    0 讨论(0)
  • 2020-12-14 09:04

    Yes, the barcode scanner is detected as a Physical Keyboard. When a keyboard is connected to the device, by default the soft keyboard is disabled. To enable it, we need to turn OFF hardware keyboard via:

    Settings > Language & Input > Select Input Method

    The option name may differ from device to device. We will be able to use the scanner along with the soft keyboard even though we turn it OFF.

    And NO, there is no way currently to programmatically accomplish this. The most we can do is detect when a scanner/keyboard is connected and redirect the user to the Input Method selection window, by overriding the onConfigurationChanged method like this:

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
    
        ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
                                      .showInputMethodPicker();
        Toast.makeText(this, "Barcode Scanner detected. Please turn OFF Hardware/Physical keyboard to enable softkeyboard to function.", Toast.LENGTH_LONG).show();
      }
    }
    
    0 讨论(0)
  • 2020-12-14 09:07

    I think you can specify in you manifest file to use on softinputmode and handle a config change for keyboard|keyboard_hidden

    0 讨论(0)
提交回复
热议问题