Hi,
I have to use a Barcode-reader in a web application and the code should be put in a jsp text field.
The barcode-reader maps the keyboard shortcut in the right way but after then sends a byte sequense like ENTER (ascii 13) and CTRL-J that open the Firefox download window.
My question is how can I disable the CTRL-J shortcut?
And if it's no possible, how can I send CTRL-J by javascript function?
Thanks
Re: How to disable CTRL+J firefox shortcut using javascript ...
function disableCtrlKeyCombination(e)
{
//list all CTRL + key combinations you want to disable
var forbiddenKeys = new Array(‘a’, ‘n’, ‘c’, ‘x’, ‘v’, ‘j’);
var key;
var isCtrl;
if(window.event)
{
key = window.event.keyCode; //IE
if(window.event.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
else
{
key = e.which; //firefox
if(e.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
//if ctrl is pressed check if other key is in forbidenKeys array
if(isCtrl)
{
for(i=0; i
Re: How to disable CTRL+J firefox shortcut using javascript ...
function disableCtrlKeyCombination(e)
{
//list all CTRL + key combinations you want to disable
var forbiddenKeys = new Array(‘a’, ‘n’, ‘c’, ‘x’, ‘v’, ‘j’);
var key;
var isCtrl;
if(window.event)
{
key = window.event.keyCode; //IE
if(window.event.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
else
{
key = e.which; //firefox
if(e.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
//if ctrl is pressed check if other key is in forbidenKeys array
if(isCtrl)
{
for(i=0; i
Re: How to disable CTRL+J firefox shortcut using javascript ...
Im doing the same, working with barcode readers.
Based on this
Workaround if you have one: In order to change a keycode, you need to cancel the current event, and dispatch a new key event with the new keycode. public class FireFoxTextBox extends TextBox { public void onBrowserEvent(Event event) { int type = DOM.eventGetType(event); if (type == Event.ONKEYPRESS) { changeKeyCode(event); } else super.onBrowserEvent(event); } public native void changeKeyCode(Event event) /*-{ if (String.fromCharCode(event.charCode) == "Q") { var newEvent = document.createEvent("KeyEvents") newEvent.initKeyEvent("keypress", true, true, document.defaultView, event.ctrlKey, event.altKey, event.shiftKey, event.metaKey, 0, "F".charCodeAt(0)) event.preventDefault() event.target.dispatchEvent(newEvent) } }-*/; }I did this
<script> function pressed(e){ if(e.ctrlKey){ e.preventDefault(); } } <script> <body> <INPUT id=barcode type=text onkeydown="pressed(event)"> </body>Use your mind :D
Post new comment