Not tested this at all, I bet there is a bug or two... not sure why you
need GM though
var lastKeyTime=new Date();
var low_threshold = 10; //assuming milliseconds, keys required to be
input with this much or less time between them
var high_threshold = 250; //assuming milliseconds between barcode reads,
to reset the system if they wait long enough
<input id="myfield" type="text" onkeyup="return barcodeonkeyup(event)" />
In your keyup listener (use
document.getElementById('myfield').addEventListener('keyup',barcodeonkeyup,false);
function barcodeonkeyup(ev){
var keytimediference=new Date() - lastKeyTime;
if(keytimediference >
low_threshold && keytimediference < high_threshold ){
// must be a keyboard input, clear your text field
// document.getElementById('myfield').value="";
ev.preventDefault()
return false;
}
lastKeyTime=new Date();
}
On Mon, Jul 23, 2012 at 6:12 AM, Prakash Ranganthan <[email protected]>wrote:
> Thanks for the suggestion I too thought that but I don't have an idea
> about how to proceed. can you help me
>
>
> On Monday, July 23, 2012 10:41:34 AM UTC+5:30, blm wrote:
>>
>> On 7/22/12 8:43 PM, Prakash Ranganthan wrote:
>> > Hi friends i tried blocking keyboard input but it also blocks barcode
>> > input any idea how to proceed with blocking only keyboard input in
>> > textbox and allowing barcode input.
>> >
>> > var barcode = document.getElementById('**userid');
>> > barcode.addEventListener("**keypress", function() { alert("Please use
>> > Barcode Scanner!"); document.getElementById('**userid').value = "";},
>> true);
>>
>> The barcode readers I've used just generate keystrokes, so as far as the
>> browser's concerned, it's all keystrokes. However, the keystrokes from
>> the reader usually come quickly and consistently, so maybe you could
>> measure the time between keystrokes and differentiate that way.
>>
>> Of course whatever reader you're using may work differently.
>>
>> Brian
>>
> --
> You received this message because you are subscribed to the Google Groups
> "greasemonkey-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/greasemonkey-users/-/YMrxvLyu8qgJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/greasemonkey-users?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en.