PDA

View Full Version : Listen to keyboard input (Barcode Scanner)



synbits
7 Oct 2013, 3:15 AM
Hello,

I'm using the extjs 4.2 with MVC structure and I'm building a single page app.
I would like to listen to keyboard inputs and do something with them.
But the things I listen to are 'Special'...

I have a Barcode Scanner wich sends a string as if it's a keyboard input.
Example:
[tab]tekstblabla[tab]
What I would like to do is have a listener in my main controller to catch this kind of keyboard input expression and use a message or alertbox to display the 'tekstblabla' piece of it.

How to? (Thinking about the init:function() in my main controller and add something to the this.listen function?)

Thanks for any reply!

existdissolve
7 Oct 2013, 5:29 PM
In my app, I simply have a change event on the target field that runs my handler code based on the barcode scanner input. The field is focused by default when the section loads, and auto-clears itself after the scan is submitted (this prevents additional scans from getting concatenated in the search field).

MonkeySleeve
8 Nov 2013, 7:33 AM
I'm also working on a app that uses a device with a build in barcode scanner(1D). And i've manage to create a listener which always listens for a keydown event even if you're not focused on a textfield. This is because we want to be able to scan at all times for nagivation purposes.

However i can't seem to get the information from a barcode within the event. When the event is triggered, the e.keyCode is always the last character of de barcode(I think, i am still unsure if this maybe is just the keycode for the button used to scan).

I'm not sure how i am able to get the data from the barcode cause it doesn't seem to register as a keyboard event... Im using a Winmate E430T. Any ideas?

bartyhoho
8 Nov 2013, 10:29 AM
I have a separate KeyboardController controller that sets up a keyDownMap on init:


Ext.define("KeyboardController", {
extend: "Ext.app.Controller",
init:function() {
var me = this;
me.keyDownMap = new Ext.util.KeyMap(document, [{
key : 17,
fn : function() {
console.log("keyboardController CTRL down press");
}
}])
}
)


Since it's attached to document, it's catching the entire application's keyboard events.

MonkeySleeve
13 Nov 2013, 3:24 AM
I've managed to find a setting on the Winmate which states; Emulate keyboard input. This way every char within the barcode is emulated as a keyboard event. So now i'm able to get the information out of the barcode.

But another problem i run into is that i'm currently using Dolphin Browser for Android 2.3 since this is the only webkit browser i could find for 2.3. And everytime i scan outside of a textfield, it starts searching the input from the keyboard event in the address bar.

I've disabled Google Search app and the suggestions within the browser this doesn't stop it from entering the input in the address bar...