21

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 force my tablet to use the physical keyboard (it thinks the scanner is the keyboard) and that prevents the virtual keyboard from coming up (which I want for some other screens). I have to manually click on the system bar to disable the physical keyboard for the virtual keyboard to popup.

So, is there a way to disable the physical keyboard in code or make the virtual keyboard come up even if some "keyboard" is connected?

Bart
  • 19,692
  • 7
  • 68
  • 77
Han
  • 620
  • 2
  • 10
  • 22
  • Exactly the same problem here, I'm developing a django application which makes use of a barcode scanner for EAN13 but also need virtual keyboard for product name, etc. My hardware is an Acer tablet Iconiatab A200 with latest Android 4.0.3... I'd really love to find a solution ! – Lapin-Blanc May 05 '12 at 06:58
  • @Lapin-Blanc you found any solution for this problem? – Mohsin Naeem Nov 22 '12 at 07:39
  • 1
    Yes, I found a solution : have a look here : http://stackoverflow.com/questions/10561760/how-to-enable-both-hardware-and-virtual-keyboards-on-android-ice-cream-sandwich/10580746#10580746 – Lapin-Blanc Nov 22 '12 at 09:15
  • @Lapin-Blanc thanks for the reference. But it is not from the code :) – Mohsin Naeem Nov 23 '12 at 19:35
  • You could include the Barcode Scanner in your application. See [ZXing](http://code.google.com/p/zxing/) – Lukas Knuth Nov 23 '12 at 20:50
  • 1
    @LukasKnuth barcode scanning is not my problem :) But the `Physical keyboard` – Mohsin Naeem Nov 24 '12 at 07:51
  • @MMohsinNaeem yes, but then you wouldn't need to connect an external barcode scanner to your tablet in the first place. – Lukas Knuth Nov 24 '12 at 10:51
  • @LukasKnuth In my case I am using a `HID compatible NFC reader` Which stops soft keyboard to poop up. – Mohsin Naeem Nov 24 '12 at 11:53
  • @MMohsinNaeem Can you modify the app or are you looking for a system-wide setting that forces the soft input method to always be displayed when an input field is selected? – Enrico Nov 30 '12 at 08:38
  • @Enrico which app? I can do any thing to achieve this :) even a root or anything, that make it possible! – Mohsin Naeem Nov 30 '12 at 09:01
  • @MMohsinNaeem I mean, do you need the keyboard to appear in an app that you are developing or that you can modify? Or is it a 3rd party app which can't be changed, but you'd like to force the keyboard anyway? – Enrico Nov 30 '12 at 09:06
  • @Enrico I want this in my app I can modify it. And app works in koisk mood. – Mohsin Naeem Nov 30 '12 at 09:07

6 Answers6

8

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)

Enrico
  • 10,377
  • 8
  • 44
  • 55
  • @MMohsinNaeem Which bluetooth(?) scanner are you using? – Enrico Nov 30 '12 at 09:26
  • How can we help you if you refuse to provide useful information? Android 4.2 is completely different than 3.0 – Enrico Nov 30 '12 at 11:16
  • I guess android > 3.0 is a correct information. Is it not? 4.2 is came after 3.0 :) so more specifically the tab I have is running custom [Mediapad_2.06.26_OsiMood](http://forum.xda-developers.com/showthread.php?t=1677281) – Mohsin Naeem Nov 30 '12 at 11:21
  • Let me know if my revised solution works. Some of these options changed between 4.0 and 4.2 and I don't have a 4.0 device to test it on. – Enrico Nov 30 '12 at 12:36
  • many thanks! but I need solution from code. Question states `So, is there a way to disable the physical keyboard in code` :) – Mohsin Naeem Nov 30 '12 at 12:42
  • "or make the virtual keyboard come up even if some "keyboard" is connected?" – Enrico Nov 30 '12 at 12:47
  • Hey Enrico. Fairly old post now but I was wondering was that a tablet or a phone you were using with Jelly Bean? It seems you can use that method with a tablet from Honeycomb to ICS but I haven't been able to use that method on a phone running the same version. If Jelly Bean can do it on a phone I may need to upgrade! – Stuart Robertson Jan 23 '13 at 10:57
  • I'm fairly certain I was on my Galaxy Nexus – Enrico Jan 23 '13 at 11:30
3

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.

Ron
  • 24,175
  • 8
  • 56
  • 97
  • thanks for the reply. But `Configuration` class just tells the status. We can not change it. here http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/com/android/systemui/statusbar/tablet/InputMethodsPanel.java#82 the `Button mHardKeyboardSwitch` handle the `Physical keyboard` May be you can help me to find what call it made to make it off. I failed to find it so far:) – Mohsin Naeem Nov 24 '12 at 07:48
  • yes I have seen this method. But I am looking for some luck. may be `Settings.Secure.putXXXX(resolver, name, value)` can help me? – Mohsin Naeem Nov 24 '12 at 08:16
  • yes I know above line only works in rooted devices. So lets assume I have a rooted device. – Mohsin Naeem Nov 24 '12 at 08:17
  • Pretty much everything works the way u want after rooting a device, but I feel your app will need to have the same `android:sharedUserId` as the settings app. Try it out. Tel me otherwise.. – Ron Nov 24 '12 at 14:31
  • I did not get how I can get it after rooting? What should be the line to make physical keyboard off? – Mohsin Naeem Nov 25 '12 at 06:27
  • Sorry.. I did not find a way to programmatically disable it even in settings code.. The settings app only hides or shows the h/w keyboard section and reflects keyboard's state in it(whether attached or detached..) – Ron Dec 02 '12 at 04:28
3

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();
  }
}
desidigitalnomad
  • 1,443
  • 21
  • 33
2

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

VivekNR
  • 41
  • 4
  • What I want is, only `Virtual Keyboard` AFAIK config change called when the keyboard is being displayed or gone. But how can I force virtual keyboard to come out when `Physical keyboard attached`? – Mohsin Naeem Nov 28 '12 at 05:52
  • Try this in you activity @Override public void onCreate(Bundle savedInstanceState) { getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } – VivekNR Nov 29 '12 at 21:24
  • Another hacky way which can be used if you are only running on an emulator would be to edit your emulator settings, uncheck the option "hardware keyboard present". That way your emulator will take input only from the onscreen keyboard. Hope this helps.... – VivekNR Nov 30 '12 at 02:55
  • I need solution when `HID device` attached to the tablet. :) – Mohsin Naeem Nov 30 '12 at 02:57
  • you should try looking into the platform and inject ur input from the NFC reader as a keyevent.... eliminates the use of a external keyboard – VivekNR Nov 30 '12 at 19:09
  • @Mohsin Naeem Did you find solution for your work. I am also facing the same issue. – Suresh Sharma Mar 21 '16 at 08:13
0

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;

Defter
  • 214
  • 1
  • 7
0

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.

Alok Tiwari
  • 354
  • 3
  • 8