mircerlancerous / cordova-plugin-keyboard

Reads external keyboard input
2 stars 5 forks source link

onKeyDown or onKeyUp callback doesn't return any result #1

Open orenagiv opened 7 years ago

orenagiv commented 7 years ago

Hey,

I've tried:

Plugin.keyboardPlugin.onKeyDown(function(success) {
    console.log(success);
}, function(error) {
    console.log(error);
});

Then verified it works by using:

Plugin.keyboardPlugin.testKeyDown(function(success) {
    console.log(success);
}, function(error) {
    console.log(error);
});

And got:

D
key down test success

(which is good)

But when I then used an external keyboard (barcode in my case) - It didn't fire any of the callback functions.

Any ideas?

mircerlancerous commented 7 years ago

Hi Oren,

Unfortunately I was unable to get this to work properly with hardware devices (that's what I need it for too). This plugin is still in development; I will update the readme to reflect that. Glad to had some success with it at least. If you've got some time to look into this I would certainly appreciate a second set of eyes. Here're some links and information that I've collected recently which I hoped would help.

https://developer.android.com/training/keyboard-input/commands.html https://examples.javacodegeeks.com/android/core/ui/events/android-physical-keys-example/

@Override public boolean onKeyUp (int keyCode, KeyEvent event){ char c = (char) event.getUnicodeChar(); //Do something.... return super.onKeyUp(keyCode, event); }

The android documentation is not very clear on how to handle key presses. There was some documentation that suggested newer versions on android might have a different way of handling key presses, but again I'm not sure. I haven't even looked at iOS yet.

orenagiv commented 7 years ago

Hey,

Thanks!

I'm also investigating and will let you know if I find a solution. 

For iOS I have a solution:

https://github.com/paragon-creations/cordova.externalkeyboard

It works great but I couldn't wrap it as a standalone Cordova plugin - it requires some manual changes to the IOS project outside the plugin.

orenagiv commented 7 years ago

I've posted this question on StackOverflow... http://stackoverflow.com/questions/41862667/cordova-plugin-for-passing-keycode-of-a-keyup-event-to-the-app

mircerlancerous commented 7 years ago

I posted something similar a while back and got no hits. http://stackoverflow.com/questions/39173850/cordova-plugin-keyboard-events-android

I installed an app that tracks all events of any kind being fired on the device, and confirmed that the key up and down events are indeed firing as expected. Doesn't help that much but at least the events are named as we thought and not something else.

orenagiv commented 7 years ago

Hey,

Here is what we are trying:

https://github.com/paragon-creations/cordova-plugin-keystrokes

In trying to consult with experienced people in this field. Hope to have some successful results soon. 

If you have any ideas - please send! :)

Regards,

Oren. 

a, pre, code, a:link, body { word-wrap: break-word !important; }

mircerlancerous commented 7 years ago

Best of luck to you. I don't currently have any fresh ideas but am hoping to have some time soon to revisit this. The best help I can offer right now is to take a look at the commit history of the repo. I tried a number of different solutions before ending on the current implementation.