Handling Keyboard Shortcuts in JavaScript

Despite the many JavaScript libraries that are available today, I cannot find one that makes it easy to add keyboard shortcuts(or accelerators) to your javascript app. This is because keyboard shortcuts where only used in JavaScript games - no serious web application used keyboard shortcuts to navigate around its interface. But Google apps like Google Reader and Gmail changed that. So, I have created a function to make adding shortcuts to your application much easier.

Update

This is the second version of this script. The following modifications were made...

The documentation for the last version is still available.

Thanks for all the comments and suggestions, guys.

Demo

Just press the shown combinations - if the script works, the status will changed to 'Called'. For example, press the key '1'...

1
Function Called : Not Yet
Ctrl+1
Function Called : Not Yet
Alt+1
Function Called : Not Yet
Shift+1
Function Called : Not Yet
Ctrl+Shift+1
Function Called : Not Yet
Ctrl+Alt+1
Function Called : Not Yet
Shift+Alt+1
Function Called : Not Yet
Ctrl+2 - Remove Shortcut
Function Called : Not Yet
If you click the 'Remove Shortcut' Link before pressing the Ctrl+2 Combination, the function should NOT be called.
3 - With disable_in_input = true
The function should NOT be called when typing '3' in the input field
Function Called : Not Yet
4
Function Called : Not Yet
This uses the 'keycode' option.
Ctrl+A - With propagate = true
Function Called : Not Yet
If Ctrl+A is pressed, it will call the function and then propagate the event to the browser - selecting the text.

Try it out...

Live Evaluation

Documentation

shortcut.add()

First Argument : The Shortcut Key Combination - String
The shortcut key combination should be specified in this format ... Modifier[+Modifier..]+Key. More about this in the Supported Keys section.
Second Argument : Function to be called - Function
Specify the function here. This function will be called if the shortcut key is pressed. The event variable will be passed to it.
Third Argument[OPTIONAL] : Options - Associative Array

This argument must be an associative array with any of these three options...

type - String
The event type - can be 'keydown','keyup','keypress'. Default: 'keydown'
disable_in_input - Boolean
If this is set to true, keyboard capture will be disabled in input and textarea fields. If these elements have focus, the keyboard shortcut will not work. This is very useful for single key shortcuts. Default: false
target - DOM Node
The element that should be watched for the keyboard event. Default : document
propagate - Boolean
Allow the event to propagate? Default : false
keycode - Integer
Watch for this keycode. For eg., the keycode '65' is 'a'.
Example...
{
'type':'keydown',
'propagate':false,
'disable_in_input':true,
'target':document,
'keycode':65
}

Example Code


shortcut.add("Ctrl+B",function() {
	alert("The bookmarks of your browser will show up after this alert...");
},{
	'type':'keydown',
	'propagate':true,
	'target':document
});

shortcut.remove()

Just one argument - the shortcut combination that was attached to a function earlier. Make sure that this is exactly the same string that you used while adding the shortcut.

Example Code


shortcut.add("Ctrl+B",function() {
	alert("Bold");
});
//Remove the shortcut
shortcut.remove("Ctrl+B");

Supported Keys

The shortcut keys should be specified in this format ...

Modifier[+Modifier..]+Key

Example...

Ctrl+A

The valid modifiers are

You can specify a sequence without a modifier as well - like this...

shortcut.add("X",function() {
	alert("Hello!");
});

The valid Keys are...

These keys are case insensitive - so don't worry about using the correct case.

This library is in beta - so expect some problems. Suggestions are welcome.

Code

Download the shortcuts.js file.

License

BSD License

Other Libraries

There is a jQuery plugin available for this library - jQuery Keyboard Hooker Plugin by Tzury Bar Yochay

If you want an easier way to generate the string for the shortcut, take a look at Jonathan Tang's Keycode.js.

Related Links

Comments

Michael at 12 Jul, 2007 11:35
Hi,

I love your scripts. They are very easy to use, they work perfect and the update with the disabling in input/textarea is the last thing I missed.

Great work, keep it coming :-)

Michael
Reply to this.
Binny V A at 13 Jul, 2007 01:58
Thanks for the encouragement :-) The new version is in beta - so please let me know if you find any problems with it.
Reply to this.
Anonymous at 13 Jul, 2007 01:18
Thank you SOOOOOOOOOO much for adding "shortcut remove" function.
Reply to this.
paolo at 13 Jul, 2007 06:47
And it works with Safari too... but I can't put an exclamation mark nor the digit 'one' in this comment because their key is binded... Safari's bad? Anyway, really nice work. Keep on.
Reply to this.
Binny V A at 13 Jul, 2007 10:45
Thats is to be expected - I did not use 'disable_in_input' for that binding. However, you should be able to use the digit '3' here - like I just did :-), as that binding has the option disable_in_input.
Reply to this.
Lalit Patel at 13 Jul, 2007 10:20
Hi Binny,
You code works just fine for me.
I was looking disabling in input/textarea feature. Its great that you added it.

Cheers :)
Reply to this.
Aaron Rosenzweig at 14 Jul, 2007 10:08
Great Script, thanks for sharing. To get the "Command" modifier of a Mac keyboard to be recognized you need to look for "Event.metaKey" just like you look for Event.shiftKey and Event.ctrlKey. The "Command" key is the one that looks like a cloverleaf and an "open apple".
Reply to this.
Ram at 15 Jul, 2007 09:25
Great work. Keep it coming
Reply to this.
esam bdair at 15 Jul, 2007 11:58
hi ..
Great Script, thanks for sharing.
i want to ask you one qustion ?
when i try to add a shortcut(Ctrl+S) it's work but after calling my function the save dialog appear how i can remove this dialog?
this is my code

shortcut.add("Ctrl+S",function() {
alert("test");
return false;
},{
'type':'keydown',
'propagate':false,
'target':document
});
Reply to this.
Mark Lewis at 20 Jul, 2007 07:53
I echo everyone else's sentiments: this is a beautiful script.

However, I can't seem to capture the following characters: , < . >

Just trying to get the ","/"<" key to work, I've tried all of the following combinations:
Ctrl+,
Ctrl+<
Ctrl+Shift+,
Ctrl+Shift+<

None of the events trigger in IE7. This may apply to other special characters as well.
Reply to this.
Seth at 20 Jul, 2007 12:58
I cannot seem to capture Ctrl+Enter in Firefox for the Mac OS X. I can capture lots of other Ctrl+ or +Enter combos, but not Ctrl+Enter. Any thoughts? Here is the command I'm testing with:

shortcut.add('ctrl+enter',function(){alert("Hello World");})

-Seth
Reply to this.
kUI at 23 Jul, 2007 07:55
This is not working with JSF...
Reply to this.
YJ at 26 Jul, 2007 12:12
Help me
i'm make test page and not execute....script error
i want know this code problem...
anyone show me correct source code ^^
thank you
=======================error source=============================================
<html>

<HEAD><TITLE>Handling Keyboard Shortcuts in JavaScript</TITLE>

<script type=text/javascript src="shortcut.js">
</script>


<script type=text/javascript >
function init() {
alert("init");
shortcut("Shift+F1",function() {
alert("Help Me!");
});
shortcut("Ctrl+S",function() {
alert("Saved!");
});
shortcut("Right",function() {
alert("Right");
});
}

</script>
</head>
<body onload ="init()">
test
</body>
</html>
======================================================================
Reply to this.
Binny V A at 26 Jul, 2007 01:12
That code is for the old version of this library. Please use shortcut.add() if you are using the latest version.
Reply to this.
Anonymous at 08 Aug, 2007 05:32
maybe use

shortcut.add( instead of shortcut(
Reply to this.
Anonymous at 31 Jul, 2007 11:15
Mr. Binny, This lib is compatible with IE6? Thanks.
Reply to this.
Binny V A at 01 Aug, 2007 05:58
Yeah - I tested it in IE6 - it worked without any problems.
Reply to this.
Anonymous at 01 Aug, 2007 06:52
Thank You, Mr. Binny. Congratulations for very well done work.
Reply to this.
Dave Myron at 24 Jun, 2008 02:48
In IE6, for me, it doesn't seem to work with single letter keys (like 'c', 'f', 'h', etc). Arrow keys are working in IE6 so there must be a bug somewhere.
Reply to this.
Anonymous at 01 Aug, 2007 07:25
Dear Mr. Binny:

this code propagate and open de file open box. But if we add a alert box in 'func' then will not to propagate. What is wrong?
shortcut.add("Ctrl+O",function() {
func("obj","id") ;
},{
'type':'keydown',
'propagate':false,
'target':document
});

function func(obj,id) {
var a;
a=1;
// if add this don't propagate. OK.
//alert("Hello Mr. Binny");
//but if remove this alert will propagate. Not OK.
}
Reply to this.
Anonymous at 03 Aug, 2007 10:56
Dear Mr. Binny:

With IE7, I add 'e.keyCode = 0;' to stop the event print for CTRL + P:
...
e.cancelBubble = true;
e.returnValue = false;
e.keyCode = 0;

But this don't work for IE6.
Thanks for your suport.
Reply to this.
Quân at 01 Aug, 2007 06:36
Thanks, thanks, thanks
Reply to this.
Chad Whitacre at 06 Aug, 2007 01:30
The "Ctrl-Alt-2" event propagates in FF <one>.5 when it shouldn't. If you have an alert in your callback it dies properly, but w/o that alert it bubbles up and switches tabs. Any ideas?
Reply to this.
Binny V A at 06 Aug, 2007 08:12
Prorogation is the issue for most people with this script. I am still looking into it.
Reply to this.
Aileen at 06 Aug, 2007 07:18
Hi, i really love your script :D
It helps me a lot for my final project.
But i was thinking, if i want to disable the printscreen by using your script.
Is it achievable?
Reply to this.
Yoga at 07 Aug, 2007 03:16
anyway, is it possible using "print screen" as a shortcut keys? actually, i wanna disable "print screen", but why "print screen" didn't detected as keypress or keydowm, though i know its ascii is 44. anybody can give any idea to solve my problem??
thanks indeed.. great script anyway..
Reply to this.
Binny V A at 07 Aug, 2007 06:01
Hmm - I did not include Printscreen in my shortcut list. An oversight on my part. I will update the script by the end of this week. I will try and make this change.

I will let you know then the script is updated
Reply to this.
Anonymous at 15 Sep, 2007 07:29
That would be awsome for protecting image of web site
Reply to this.
Anonymous at 22 May, 2008 09:25
It doesn't protect anything ... javascript is client side, you can't trust client side
Reply to this.
pekue at 08 Aug, 2007 03:22
Hi Binny and yall,

I just started to work my way into your script - fantastic lib, simply working and what I was looking for: thnx.
I found a single issue: is it true that there is no way to capture the release of the keyup of a pressed standalone ctrl?
shortcut.add('c',function(){cPressed=true;},{'disable_in_input':true});
shortcut.add('c',function(){cPressed=false;},{'disable_in_input':true,'type':'keyup'});
works as expected
shortcut.add('Ctrl',function(){cPressed=true;},{'disable_in_input':true});
shortcut.add('Ctrl',function(){cPressed=false;},{'disable_in_input':true,'type':'keyup'});
sets cPressed to true but not back to false :(

Id love to hear from you and once again:
thnx for you great work

pekue
Reply to this.
Binny V A at 17 Aug, 2007 01:09
That will not work. You have to do this...


var cPressed = false;
shortcut.add('Ctrl',function(){
cPressed = (cPressed) ? false : true;
},{'disable_in_input':true,'type':'keyup'});
Reply to this.
Anonymous at 05 Dec, 2007 04:45
Can any give a better explanation how to use 'this' in this shortcut. Using this can i add shortcuts to particular controls/iframe....
Reply to this.
Nitin at 08 Aug, 2007 11:10
This is excellent. Thanks for putting it up.
Reply to this.
BradW at 09 Aug, 2007 09:24
So, I like what I see. We have a need to also use the F4 key. Looks like we can trap it, but the event still gets propogated as we also get the address list after trapping the event. The same thing happens when I try Alt+F4. We trap the event and do our stuff, then explorer closes.

Thoughts on this? Is there a way around this?
Reply to this.
Binny V A at 09 Aug, 2007 02:25
I think F4 issue can be solved - but I cannot do anything about Alt+F4. That is handled by the OS and not the browser. JS can do nothing about that.
Reply to this.
Narendra Naidu at 30 Aug, 2007 04:49
Function keys such as F-four and F-five are still getting propogated?
Is there any way out?
Reply to this.
joo at 12 Aug, 2007 10:10
thanks for your present
I like it very much
Reply to this.
Jason at 13 Aug, 2007 11:38

I can't seem to get CAPS lock to work on the Mac (haven't tried a PC yet) in Safari/Firefox 2.0.0.6/Camino .5

Thanks for this script.

Jason
Reply to this.
Blake at 17 Aug, 2007 05:14
I've got some warnings in Firefox Error Console:
1) assignment to undeclared variable shortcut
2) anonymous function does not always return a value

Easy to correct:
1) var shortcut = { (add "var")
2) "return undefined" instead of plain "return" in function "func" ?

Someone may integrate this into a larger application, so better to prevent any additional warnings :)
Reply to this.
Binny V A at 18 Aug, 2007 02:08
I am not getting any errors. Anyone else seeing this error? If so, what is the version of your Firefox?
Reply to this.
Phil Nelson at 22 Aug, 2007 02:33
Is there a problem with IE7 and propagation ?

I've bound F1 to an alert, and the dialog box pops up fine. Nothing else happens on Firefox (even although without the binding it would pop up the help) but on IE7 it also switches to the Help screens.

Apart from that the library is wonderful.

Thanks

Phil Nelson
Reply to this.
Anonymous at 24 Feb, 2009 07:06
This should help:

document.onhelp = function () { return false; };
Reply to this.
Michal Till at 22 Aug, 2007 06:48
This might be handy for someone: www.json.cz/canceling-browsers-keyboard-shortcuts
Reply to this.
John at 23 Aug, 2007 02:31
Any ideas on getting the ? key to work?
I've tried

Shift+/
?
Shift+?
/

No luck :( also Shift+3 is a bit funny in safari, it seems to do the action of the last pressed shortcut.

Cheers for the great script
Reply to this.
Patrick at 28 Aug, 2007 12:49
Hi,
great work on this script. Easy to use, working on all browsers and efficient.
I took the liberty to add a feature that I use all the time: the ability to add an execution scope to the callback function. All my javascript code is structured in classes, and when I declare a shortcut inside a class, I want the callback function to have access to the "this" variable as well.

Below is my modification of the add function for this in case you are interested:

Line 309, replace:
callback(e);
with:
if(typeof obj == "object" && scope == true) {
  obj.tmpShortcutCallback = callback;
  obj.tmpShortcutCallback(e, obj);
  delete obj.tmpShortcutCallback;
}
else {
  callback(e, obj);
}
AND add this to the "add" function definition:
'add': function(shortcut_combination, callback, opt, obj, scope) { ...

You will then be able to do stuff like this:

foo = {
    id: 5,
    bar: function() {
        alert(this.id);
    },
    init: function() {
        uic.shortcut.add("Shift+V", this.bar, {}, this, true);
    }
}

foo.init();
Cheers for the good script.
Patrick
Reply to this.
Binny V A at 29 Aug, 2007 07:23
Thanks for giving back the code - I will try to include this functionality in the next version. If you have anymore suggestions, dont hesitate to shoot me an email.
Reply to this.
Anonymous at 31 Aug, 2007 02:17
CTRL+S opens the save dialog too in FireFox.
shortcut.add
("Ctrl+S", function()
{
alert("You have pressed CTRL+S");
return;
}
,
{
'type':'keydown',
'propagate':true,
'target':document
}
);
Reply to this.
Paolo Dona at 21 Sep, 2007 01:56
I could stop the CTRL-S event from propagating (and thus showhing the 'save as...' dialog in firefox) just using 'keypress'

shortcut.add("Ctrl+S",
function(evt) { alert('it works'); },
{'type':'keypress','propagate':false,'target':document}
);

tested with Fireox 2.0.0.7
Reply to this.
kp at 20 Jan, 2009 01:44
first off, thanks for the extremely helpful keyboard shortcut JS code with examples! This shortened my many hours of scouring the web into 5 minutes. Had a little trouble with Ctrl+S in Firefox, but Paolo Dona (21 Sep, 2007 01:56) gave the "keypress" tip (which I didn't really see in the instructions until that was pointed out), which worked perfectly. thanks again, and keep the good stuff coming!
Reply to this.
Anonymous at 31 Aug, 2007 02:18
Having the below script and pressing CTRL+F4 shows 2 alert ( for ctrl+f4 and the other for ctrl+s)
< script>
shortcut.add
("Ctrl+S", function()
{
alert("You have pressed CTRL+S");
return;
}
,
{
'type':'keydown',
'propagate':true,
'target':document
}
);

shortcut.add
("Ctrl+F4", function()
{
alert("You have pressed CTRL+F4");
return;
}
,
{
'type':'keydown',
'propagate':true,
'target':document,
'keycode':115
}
);
</ script>
Reply to this.
Parthibhan at 07 Jan, 2009 12:51
Hi,

I am using Mozilla Firefox 3.0.5 . While i am pressing Ctrl+F4 , the alert is coming instead of pressing
Ctrl + S .
please give me a step to solve my problem. The code is

shortcut.add
('Ctrl+S', function()
{
alert('Hi');
return;
}
,
{
'type':'keypress',
'propagate':false,
'target':document
}
);

Thanks & Regards,
S.Parthibhan .
Reply to this.
Andrea at 11 Jun, 2009 01:54
hi all,
to solve the F4, F5, F6 problem try this:

var precedente = 0;
shortcut = {
...
var ele = opt.target;
if (typeof opt.target == 'string') ele = document.getElementById(opt.target);
var ths = this;
shortcut_combination = shortcut_combination.toLowerCase();

//the function to be called at keyup
var funcReset = function(e) { precedente = 0; }

//The function to be called at keypress
var func = function(e) {
e = e || window.event;

...
if (code == 188) character = ","; //If the user presses , when the type is onkeydown
if (code == 190) character = "."; //If the user presses , when the type is onkeydown

// The user press "s" key and not only the F4 key
if ((code == 115) && (precedente == 83)) {
code = 83;
}
else {
// The user press "t" key and not only the F5 key
if ((code == 116) && (precedente == 84)) {
code = 84;
}
else {
// The user press "u" key and not only the F6 key
if ((code == 117) && (precedente == 85)) {
precedente = code;
code = 85;
}
else {
precedente = code;
}
}
}

var keys = shortcut_combination.split("+");
//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
var kp = 0;
...
//Attach the function with the event
if (ele.addEventListener) ele.addEventListener(opt['type'], func, false);
else if (ele.attachEvent) ele.attachEvent('on' + opt['type'], func);
else ele['on' + opt['type']] = func;

//Attach the function with the event funcReset
if (ele.addEventListener) ele.addEventListener('keyup', funcReset, false);
else if (ele.attachEvent) ele.attachEvent('onkeyup', funcReset);
else ele['onkeyup'] = funcReset;

},
...


ciao
Andrea
Reply to this.
Omar at 03 Sep, 2007 10:18
Hi, thanks for the script

I use the script in a web aplication, and i need a shorcut to submit a form, I use too the form plugin of jQuery.

I have a big problem, when I pulse F4 for submit the form, the form submit many times, one, two, three, or any. I dont understand why because I only submit one time.

I need your help, tks
Reply to this.
Tzury Bar Yochay at 08 Sep, 2007 09:08
There is a version of this library as jQuery-plugin which might be good in case you are using jQuery Forms plugin
Reply to this.
Ken at 05 Sep, 2007 10:10
Is there a way to block backspace as shortcut for "Back"? I've tried adding a shortcut for backspace with a simple alert, but it performs a Back and then displays my message.

Is there a way to handle mousewheel up and down? shift+mousewheelup is another shortcut for Back which I would like to block.
Reply to this.
Flo at 06 Sep, 2007 08:46
Hey, Thanks for this library, you did a great work here!

This script is working pretty well except for "Ctrl+B" which is still propagated and display my bookmarks in Firefox 2.
Any idea on how to go over this ?


Reply to this.
yangbo at 11 Sep, 2007 08:17
之前用的是你的第一个版本,很好用,很简单,方便,但是当我想要去掉快捷键时,确找不到这个方法。我又来到你的网站,看到你改进后的版本,我很开心。非常感谢你的代码。
也许你看不懂这汉字。
Thank you very much!
Reply to this.
yangbo at 11 Sep, 2007 08:20
Thanks for this library.
Thanks for function "remove()".
Reply to this.
NitinR at 17 Sep, 2007 05:47
I love your scripts. They are very easy to use and perfect.
Excellent..Great work.

Thanks you very much for this library.
Reply to this.
Pete Warden at 20 Sep, 2007 05:57
Thanks for this, great work! I've been wrestling with similar issues on my Firefox extension, Google Hot Keys. I've found it impossible to block the propagation of the down arrow, it always ends up moving the page down. I see the same thing happen if I test this code:
shortcut.add("Down",function() {
alert("Hi there!");
},
{
'propagate':false,
'disable_in_input':true,
}
);

Is that something you've run across, or have any ideas on? Thanks,

Pete
Reply to this.
jerone at 05 Oct, 2007 07:38
Looks like a very interesting script, but i'm having the following problems -with the newest browsers atm- so far:
FF2 > can't use the numpad numbers,
Opera 9.2 > Alt + any number doesn't work,
IE7 > also can't use the numpad numbers.
Reply to this.
Anonymous at 26 Oct, 2007 08:01
Same issue...
Reply to this.
Anonymous at 05 Nov, 2007 05:58
Narf

Define in shortcut.js this:
'num0' :96,
'num1' :97,
'num2' :98,
'num3' :99,
'num4' :100,
'num5' :101,
'num6' :102,
'num7' :103,
'num8' :104,
'num9' :105,

then

shortcut.add("num0",function() {
alert("num0");
});
Reply to this.
Chirag Prajapati at 04 Jun, 2008 12:39
hi i have the same problem that numpad keys are not working 1-9 in FF,Ie and safari...
does anyone has solution then plz mail me.

Thanks
Reply to this.
Keyaudioads at 01 Feb, 2009 10:55
To operate NumberPad numbers when in Number_Lock mode add the following to 'var modifierMapping

0:'0',1:'1',2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'8',9:'9'
Reply to this.
Anonymous at 02 Feb, 2009 04:44
actually scrap that, it breaks the script and makes any key operate whatever function your running.
Reply to this.
naugtur at 24 Nov, 2008 05:13
When using iframe in designMode shortcuts defined in the document inside iframe work in FF, no reaction in Opera.
Reply to this.
naugtur at 24 Nov, 2008 05:14
When using iframe in designMode shortcuts defined in the document inside iframe work in FF, no reaction in Opera.
Reply to this.
Furkan at 11 Oct, 2007 04:14
Your script is really awesome, good job.

I ve question,

can we define all keys?I mean any keys of keyboard.
Reply to this.
vanvan at 17 Oct, 2007 04:46
When and set some key already used by the Firefox (Ex: Crtl + N) it performs the action of the script and after the browser, something that would not perform the action of the browser?
Reply to this.
Anonymous at 18 Oct, 2007 09:59
I'm trying to remove ctrl a but it seems to still be working.
shortcut.remove("Ctrl+A");

is this all i need?
Reply to this.
Binny V A at 18 Oct, 2007 09:34
If you have defined that shortcut, thats all you need. Please keep in mind that the shortcuts provided by the browser cannot be removed like that.
Reply to this.
Johnny at 18 Oct, 2007 05:06
I'll just say WOW
Reply to this.
Johnny at 18 Oct, 2007 05:07
BETTER ...

I'll just say WOW and THANKS man.
Reply to this.
Anonymous at 18 Oct, 2007 11:53
Hi All,

I would like to use this function to disable F3 function in IE so that my Flash Application can use that. But still it opens up the search function. How is it? I had given propagate : false also. Nothing happens. Am I doing something wrong...

shortcut.add("F3",function() {
alert("Hi there!");
},{
'propagate':false
}
);
Reply to this.
Steffen at 31 Oct, 2007 08:53
great work, very useful for me, get on with it!
Reply to this.
TRS at 03 Nov, 2007 07:06
Man , your js shortcut was fabulous. Only thing that is lagging how to make it work across frames.And one more thing I have two shortcuts (Ctrl+T and Ctrl+F5). On pressing Ctrl+F5 both the events are fired.

Note: As far you scripts propagation issue are considered. In I.E make e.keycode = 0 for special shortcuts like Ctrl+F and F5. As firefox is considered, event.preventDefault() works only on keypress. Hence use keydown in I.E and keypress in FireFox.
Reply to this.
TRS at 04 Nov, 2007 08:51
and same problem with iFrames.
Reply to this.
Anonymous at 07 Nov, 2007 07:59
I need to use this keys: '+' and '-'.
It would be great that for a new version of the library this keys will be implemented
Thankz
Reply to this.
Chacho at 03 Dec, 2007 06:01
Thx for this ;)
Reply to this.
Manny at 04 Dec, 2007 04:36
Thanks for the script man. This solved my problem. I'm converting a DOS based program to web-based and the client wants to have the same shortcut keys. I thought something like this was impossible in browsers and I was looking at the limited capabilities of accesskey.

This is just awesome.
Reply to this.
trs at 05 Dec, 2007 05:27
The shortcuts do not work on if focus is on any flash object/objects, can any one help.

Reply to this.
trs at 05 Dec, 2007 05:31
How any explain how use 'this' for this shortcut script . can we target particular controls or frame objects.
Reply to this.
trs at 05 Dec, 2007 09:01
event capturing gives permission denied error.
Reply to this.
trs at 05 Dec, 2007 02:11
use below code to make + and - work:
//Find Which key is pressed
var code =0;
if (e.keyCode)
{
code = e.keyCode;
if(code>90)
code= code - 64;
}
else if (e.which) code = e.which;
Reply to this.
trs at 05 Dec, 2007 04:34
more over to make '+' work , use other name say 'plus' : make this modification in shortcut.js

for(var i=0; k=keys[i],i<keys.length; i++) {
//Modifiers
if (k == 'plus')
k = '+';
Reply to this.
trs at 05 Dec, 2007 04:34
shortcut.add("Ctrl+plus",
Reply to this.
trs at 05 Dec, 2007 04:35
I have one question : how to stop propogation alt+F, alt+e ,...in IE?
Reply to this.
Binny V A at 05 Dec, 2007 08:38
> I have one question : how to stop propagation alt+F, alt+e ,...in IE?
Try
shortcut.add("Alt+f",function(e) { alert('it works'); },{'propagate':false});
If that did not work, try with a different event
shortcut.add("Alt+f",function(e) { alert('it works'); },{'type':'keydown', 'propagate':false});
or
shortcut.add("Alt+f",function(e) { alert('it works'); },{'type':'keyup', 'propagate':false});
or
shortcut.add("Alt+f",function(e) { alert('it works'); },{'type':'keypress', 'propagate':false});

Hopefully, one of these will work - but there is no guarantee.
Reply to this.
Anonymous at 07 Dec, 2007 04:06
propagation is not stopping in case Alt+D,Alt+F,......
Reply to this.
Anonymous at 09 Dec, 2007 11:49
Hello. First of all, please, sorry my poor english.

I have certain little problem with shorcut.js in the case of assign "t" key and not F5 key. In this case, when you press the F5 key shorcut.js trigger the event assigned to the "t" key.

The same issue with the "s" and F keys, and for the "u" and F6 keys. You can obtain information about this issue in this link of the jQuery hotkeys plugin page.

I dont now if is the better way, but, the above issue can fixed adding this lines of code before the line forty six of shortcut.js:


// The user press "s" key and not only the F4 key
if( (code == 115) && (character == 's') ) character = '';
// The user press "t" key and not only the F5 key
if( (code == 116) && (character == 't') ) character = '';
// The user press "u" key and not only the F6 key
if( (code == 117) && (character == 'u') ) character = '';


Hope be usefull for anyone. Thanks a lot for your shortcut.js library :)
Reply to this.
Anonymous at 12 Dec, 2007 01:35
nice thing, that solved all my shortcut problems and saved a lot of time.
Thumbs Up!
Reply to this.
Varun.Paval at 14 Dec, 2007 02:57
Hi Binny,

Its really interesting...

Varun.P
Reply to this.
jakjr at 19 Dec, 2007 05:08
Great Script.

only one thing:
This code doesnt work on I.E. Only with keydow:

shortcut.add("Down",function() {
alert("Hi there!");
},
{'type':'keypress'}
);

Any sugestions ?
Reply to this.
jakjr at 19 Dec, 2007 06:01
The answer:
unixpapa.com/js/key.html

Thanks
Reply to this.
Scott at 24 Dec, 2007 03:21
Thank you for making this elegant solution available.
Reply to this.
LJ at 25 Dec, 2007 09:25
can i create a hotkey for input-text? which onMouseDown event.
Reply to this.
LJ at 25 Dec, 2007 09:30
can i create a hotkey for input(text) form only, which in onMouseDown,OnKeyPress events..
Reply to this.
Anonymous at 08 Jan, 2008 12:24
quick and dirty way to stop propagating key events in IE is to set event.keyCode=0
Reply to this.
Kailash Dhondiyal at 23 Nov, 2008 10:30
Please tell me where to write event.KeyCode=0 in script. If possible then give an example.
Reply to this.
gad at 09 Jan, 2008 07:02
good solution. thank you
Reply to this.
Anonymous at 17 Jan, 2008 04:44
So how about the problem of the Print Screen key ... i'm trying to catch event from print screen key pressed but unfortunatly it doesent work in IE 7.
Have some ideea??
Reply to this.
Anonymous at 20 Jan, 2008 02:10
What about the windows key? or the Apple Key?
Reply to this.
Anonymous at 22 Jan, 2008 04:40
pls help me how to disable ctrl+n key in text field...........on keypress,keydown is not working on the press of ctrl+n keys
Reply to this.
Wouter van Reeven at 24 Jan, 2008 02:51
Hi,


Thanks for this great piece of work. Totally excellent. Too bad I cannot type exclamation marks in this editor ;-) Anyway, I too ran into differences between FF and IE. The difference with keypress and keydown is annoying when trying to develop web apps that will be used on FF and IE. In order to solve this issue, I added thses lines to your script

var keyEvent = 'keydown';
if (navigator.appVersion.indexOf("MSIE")==-1) {
keyEvent='keypress';
}

Then I modified the defaults as follows:

var default_options = {
'type':keyEvent,
'propagate':false,
'disable_in_input':false,
'target':document,
'keycode':false
}

This basically solves my issue, at least under Windows. I haven't tried this with Linux yet but will. Please consider adding these lines to your otherwise great script or tell me if there are any issues with this "solution".


thanks, Wouter
Reply to this.
Wouter van Reeven at 24 Jan, 2008 03:03
OK I now also tried this in FF under Linux (actually IceWeasel under Debian but that is FF) and also IE6 under Linux (using the ielinux project) and in these two versions this also works.


Wouter
Reply to this.
Anonymous at 24 Jan, 2008 03:59
well, i tried and it worked.
i want to know that
if i press P
is there anyhow that ctrl+p is executed followed by Atl+r followed by Alt+l
This is done to set printer setting to Landscape.
Reply to this.
Paul at 31 Jan, 2008 06:51
Hi,
Good work. Works good.
I added a help function.
something like this:

// get a html overview of all the current shortcuts
'getShortCutsInfo':function() {
var str = '<table style="margin: 10 10 10 10">';
for (prop in this.all_shortcuts)
{
str += '<tr><td align="center">' + prop + '</td><td> - ' + this.all_shortcuts[prop].description + '</td></tr>';
}
str += '</table>';
return str;
}

and don't forget to add
'description':'unknown'
around line 17
and
'description': opt['description']
around line 203

print this list in an alert or a modalwindow
Regards
Reply to this.
Anonymous at 01 Feb, 2008 02:10
could anyone make this work as a script using greasemonke? so it could be used as a shortcut for browsergames e.g.?

great work by the way
Reply to this.
Anonymous at 07 Feb, 2008 07:52
How make this script on if design mode is "on" for iframe/html
Reply to this.
Anonymous at 09 Feb, 2008 09:29
Thanks for the code. I used it to add keyboard shortcuts for navigating through my photo gallery.
Reply to this.
Anonymous at 11 Feb, 2008 05:58
Just a side note having come upon this site, you cannot catch print screen on a keydown or keypress event. Browsers are very funny with print screen, IE will not let you capture it (Version 7 onwards I believe). Firefox and a select few others will let you, however it is a fussy and buggy key and uses keyup.
Other than that, you're a bit screwed for a decent/easy way to capture it. Perhaps consider some other language if you require it; maybe even a little applet?

Crisp
www.crispycrisp.org
Reply to this.
Anonymous at 15 Feb, 2008 12:48
Variables "code" and "k" have global scope.
Here is the patch.

44d43
< var code;
145d143
< var k;
225a224
>
Reply to this.
Chat at 17 Feb, 2008 06:44
Perhaps consider some other language if you require it; maybe even a little applet?
Reply to this.
Anonymous at 18 Feb, 2008 12:36
Please suggest me the solution for IE6 to cancel event when user press esc key.It stops the downloading process in my web application.
I have tried-event.returnValue=false,
return=false,event.keyCode=0,
event.Cancel=true,
event.cancelBubble=true.But it is not working.
Reply to this.
iddaa at 19 Feb, 2008 04:16
This is a great script that i need.
thank you very much.

regards
Reply to this.
Anonymous at 22 Feb, 2008 06:19
Thank you for making this elegant solution available.
Reply to this.
Anonymous at 27 Feb, 2008 03:09
Hi, I'm using prototype.js and rico.js in the same page that I want to use shorcut.js. The problem is that in this page it don't load the function. If I remove ajax function it's work.

On the other hand, works fine in Mozilla, but I need to work in IE, any idea about that?

I've tested with different version of rico and prototype, but not work. I need to solve my problem asap.

Regards.
Reply to this.
Anonymous at 29 Feb, 2008 05:11
Hi, I'm using prototype.js and rico.js in the same page that I want to use shorcut.js. The problem is that in this page it don't load the function. If I remove ajax function it's work.

On the other hand, works fine in Mozilla, but I need to work in IE, any idea about that?

I've tested with different version of rico and prototype, but not work. I need to solve my problem asap.
Reply to this.
Anonymous at 04 Mar, 2008 12:50
Hello,

I used javascript(.js) file for adobe illustrator cs. Now i like to add shortct key for my .js file. Could you please advice me.

Thanks,
Sel.
Reply to this.
Álvaro G. Vicario at 04 Mar, 2008 09:31
I see some webmasters pretend to disable the "PrintScr" in order to "protect" site contents. There s-o-o-o-o-o many ways to override this that only completely inexpert users will be stopped. On the way, you can create lots of annoyances to the rest of the world (just think of all those stupid "Disable right-click" scripts out there that popup up even with the left button if you just don't browse with IE).

Would you take the risk of making your site unusable so it can't be stolen by some hypothetical leecher who won't have the ability to do anything with it?
Reply to this.
Anonymous at 06 Mar, 2008 02:32
is there a way to enable/dissable shortcuts by clicking checkbox using cookies.
and i there a way to redirect to another page in a different frame with target.
Reply to this.
Anonymous at 10 Mar, 2008 09:08
I have a question, how can I use this, only when I hit a key inside a input box or a asp textbox control?? How can I use de 'target' property ??
Reply to this.
Anonymous at 11 Mar, 2008 12:13
Other than that, you're a bit screwed for a decent/easy way to capture it. Perhaps consider some other language if you require it; maybe even a little applet? cet
Reply to this.
Anonymous at 12 Mar, 2008 08:43
Can I invoke Ctrl+f (Find in IE) through a mouse click using javascript.

thanks for your help
Reply to this.
Anonymous at 17 Mar, 2008 01:18
First of all, excellent library.
I'm trying to use the library to popup a window when the user presses a function key. The url of the popup window would change based on the textbox.
I'm using ASP.NET as development environment.

Is it possible to have like target a asp TextBox, i.e. target:TextBox2

Thanks, Blerim
Reply to this.
Anonymous at 18 Mar, 2008 04:43
Thanks On the other hand, works fine in Mozilla, but I need to work in IE, any idea about that?

Reply to this.
Anonymous at 18 Mar, 2008 10:27
Is there a way to capture a range of characters ('a'-'z','A'-'Z',' ','0'-'9'? I'm trying to update the innerHTML of a label on the fly... ;-) Thanks for the script - it's helped IMMENSELY....
Reply to this.
JT at 22 Mar, 2008 10:37
Hi, thanks by the library.
-keypress- does not work for me. Happens the samething with keypress such as keydown. I suposse keypress is activated just when you hold pressed the keyboard button. Please explainme what is the correct way. Thanks again.
Reply to this.
Anonymous at 27 Mar, 2008 06:58
very good thank you
Reply to this.
Anonymous at 31 Mar, 2008 04:35
is there a way to enable/dissable shortcuts by clicking checkbox using cookies.
and i there a way to redirect to another page in a different frame with target.
Reply to this.
Anonymous at 31 Mar, 2008 04:36
is there a way to enable/dissable shortcuts by clicking checkbox using cookies.
and i there a way to redirect to another page in a different frame with target.
Reply to this.
Anonymous at 31 Mar, 2008 04:52
Hi, thanks by the library.
-keypress- does not work for me. Happens the samething with keypress such as keydown. I suposse keypress is activated just when you hold pressed the keyboard button. Please explainme what is the correct way. Thanks again.
Reply to this.
Grup Hepsi at 03 Apr, 2008 01:50
very good thank you
Reply to this.
Anonymous at 09 Apr, 2008 08:51
Hi,
Thanks a lot to provide such a great script. As my requirement is as follows:
when i open a modal dialog window through java script, i don't want to allow user to take print screen. how to disable print screen. also tell me is there any way by which I can enable java script at client machine if it is disable.
Rajeev
Reply to this.
Scippie at 12 Apr, 2008 07:26
Just what I needed!!! Thanks!!!
Reply to this.
Emon at 13 Apr, 2008 12:28
You are a pioneer. Thanks tends to infinity for you effort. gr8 ( *_* )
Reply to this.
Anonymous at 16 Apr, 2008 11:23
Thanks and Kudos for this really simple and easy to use library. Can anyone tell me why does it not work with IE6 and Mozilla, It works just fine with IE7 Is any patch work required????
Reply to this.
China Landscape at 17 Apr, 2008 08:10
It works great and can disable the dialog box like save pag as... when ctrl+S.

Very simple to use, and works well with FF and linux

Thanks
Reply to this.
sahibinden at 21 Apr, 2008 08:05
woow great script.
thank you very much
Reply to this.
Dave at 23 Apr, 2008 12:31
Think I've found a bug. If I've told the script to ignore shortcut keystrokes when a form-element has focus with "disable_in_input" it works for everthing execpt select boxes. While a user can't type in a select box, they may hit a character that has been bound to a shortcut in order to jump forward in the list. I had to add:

|| element.tagName == "SELECT"

to the code where it shows:

if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;

This will prevent the shortcut from being called when the user is working with an active select-box.

Reply to this.
govind at 24 Apr, 2008 06:46
excellant work Binny. I have a question. Iam working with multiple iFrames. How can I propogate events fired in one iFrame to another iFrame, so that actuall work happens in second iFrame?
Reply to this.
Anonymous at 25 Apr, 2008 11:41
Is there is any way we can stop going to another IE or App using Alt+Tab using this script?? i tried but doesn't seems to work. Can anybody capture those keystokes and restrict its event to not to trigger
Reply to this.
Anonymous at 01 May, 2008 01:28
this wery nice script thanks
Reply to this.
vuha at 02 May, 2008 05:48
Great script. It helped me with alot of issues. However, there remains a problem with IE6.0 and iframes. I added an iframe on a test page that was working perfectly (use this page for example). This caused the shortcut keys to stop working. Clicking anywhere on the main document cause the shortcut keys to start working again. Anyone have ideas?

Thanks.
Reply to this.
Anonymous at 02 May, 2008 06:28
i have a drop down menu which has menu which comes on mouse move.i want to create short cut keys for this menu items.how to do it??
Reply to this.
Anonymous at 02 May, 2008 10:54
Im not a JavaScript geek but would love to get asistance from you on how to use this script so can be called and be active on page load. My intention is to disable use of keyboard shortcuts on a web page in a javascript enabled browser.
Thanks in advance
Reply to this.
Anonymous at 03 May, 2008 03:06
wow very good work. this will help me quite a lot in my projects and it is very user friendly. thus thanks very much.
Reply to this.
sakarya at 08 May, 2008 02:42
this wery nice script thanks
Reply to this.
şiir at 08 May, 2008 02:42
wow very good work. this will help me quite a lot in my projects and it is very user friendly. thus thanks very much.
Reply to this.
Anonymous at 09 May, 2008 10:39
please help me to find the new version of the js file.
Reply to this.
Anonymous at 09 May, 2008 11:24
well here are some others scripts Anonymous :

www.google.com/search?hl=en&q=javascript+shortcuts

Reply to this.
Steve at 12 May, 2008 07:23
Thanks for the great work. Its good to have this universal script for shortcuts. One problems I've come across though is getting the follow piece of code working in Firefox on the Mac (version 2.0.0.12 tested but not working in other versions too).

shortcut.add('esc',function() { window.location='http://www.google.co.uk'; });

I have to use escape, which is a shame since the window.location function works with other shortcuts (CTRL+SHIFT+X for example). Also if you put an alert tag infront of the window.location it also works. But the code above does not. Any suggestions on how to implement this would be greatly appreciated (again it works fine in everything except Firefox on the Mac).
Reply to this.
Anonymous at 15 May, 2008 03:13
Thanks for this code it is great. I have it working with the alerts. I don't think these are utilised enough in web apps.

I want to use this to simply update my form. The save button saves and closes, whereas update saves and stays on the form, with the updated info using php.

How to I code, if they update with the shortcut Ctrl+U then submit the update button.

I have tried "document.searchemployee.update.submit()" but no joy.

Any help appreciated.

Reply to this.
Cristiano Betta at 21 May, 2008 06:24
Wow dude, very cool little script. Made me very happy.
Reply to this.
Yarn at 29 May, 2008 01:33
Really great script.
thank you very much
Reply to this.
Chozero at 29 May, 2008 02:25
Great job,
thank you too.
Reply to this.
Anonymous at 05 Jun, 2008 11:53
This script is excellent. However, I am having problems getting it set up.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="/appname/js/shortcut.js"></script>
<script type="text/javascript">
shortcut.add("X",function() {
alert("Hello!");
});

</script>
</head>
<body>
<div>HELLO</div>
</body>
</html>
The scripts execute as I can set alerts inside them to verify they are getting called however, the added short cut does not function. Thoughts?
Reply to this.
Alexander Werner at 06 Jun, 2008 04:54
Finally a tutorial that the average joe can understand and implement. Nice work
Reply to this.
Anonymous at 06 Jun, 2008 07:35
Hello,

Great Job, excellent script. But have a problem with the following code. I want to capture keyup event on ctrl key.This is not working in IE. Can anyone solve my problem.

Thanks in advance,
Abhishek Goud.

----------------------------------------------------------------------------
****************************************************************************
----------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="shortcut.js"></script>
</head>

<body>
<script language="javascript">
shortcut.add("Ctrl",function() {
alert("Ctrl keyup...");
},{
'type':'keyup',
'disable_in_input':true,
'propagate':false,
'target':document
});

</script>

</body>
</html>
----------------------------------------------------------------------------
****************************************************************************
----------------------------------------------------------------------------
Reply to this.
Anonymous at 06 Jun, 2008 11:04
Its an excellent script, easy to use and created to perfection.
Can anybody tell me how to suppress Alt+Enter key combination in IE7


Thanks.
Reply to this.
Anonymous at 12 Jun, 2008 05:41
ALT+F4 in IE not stopped.
Solution?
Reply to this.
Binny V A at 12 Jun, 2008 08:20
I don't think that's possible - Alt+F4 is a captured by the OS - not the browser. Javascript can only access events captured by the browser.
Reply to this.
Anonymous at 12 Jun, 2008 07:07
I cannot get this script to work in Firefox 3.

However, the jquery plugin version works just fine.

Can anyone else confirm that this script works in FF3?

I am currently using Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008051206 Firefox/3.0

I would prefer to not have to use jQuery.
Reply to this.
bishal at 12 Jun, 2008 09:29
Thanks for a mar.vellous script. I was in desperate need of implementting of shortcut keys to my project
Reply to this.
Anonymous at 13 Jun, 2008 07:28
Excellent, just what I was looking for.
Reply to this.
Anonymous at 17 Jun, 2008 06:22
Hi, I have IE 7.0 and I am trying to use (page load) in ASP.NET 2005, but I get message the 'shortcut' is undefided...
What could be the problem ? Thanks

Me.Controls.Add(New LiteralControl("<script> shortcut.add(" & """" & "ALT+1" & """" & ",function() {alert(" & """" & "Hi!" & """" & ");}); </script>"))
Reply to this.
Dave Myron at 24 Jun, 2008 01:53
Single letters don't seem to work with this script in Firefox (3, at least).

In the text area above, execute:
shortcut.add("c",function() {
alert("Hi there!");
});

Then try hitting 'c'. Nothing happens for me except that the mouse pointer disappears until I move the mouse again. Accunote's keyboard shortcut javascript library works though.
Reply to this.
Dave Myron at 24 Jun, 2008 02:19
Ah, found out the problem. The script doesn't toLowerCase() the output of String.fromCharCode(code). Changing that line to var character = String.fromCharCode(code).toLowerCase() makes it work

Cheers,
Dave
Reply to this.
Jeroen at 17 Jul, 2008 01:14
Thanks Dave,
I was having that same problem.

And thank you Binny [exclamation mark]
Great work
Reply to this.
Stephen at 04 Jan, 2009 08:22
OMG this was killing me.

This fix is absolutely required if you set your key combo in ****uppercase**** "CTRL+S" or "ctrl+S" etc. will fail without this
Reply to this.
stefano at 03 Jul, 2008 03:07
Shortcuts for me doesnt work if i add toLowerCase() with firefox and opera (running linux os) :)
Reply to this.
Anonymous at 03 Jul, 2008 02:43
Thank you
Reply to this.
Indris at 07 Jul, 2008 03:51
Hello
Does the stopPropogation work if type is "keyup" for the key "down" (arrow)?
I tried with this script, and it did scrolled down, when I pressed down arrow.
I guess, if I do not want the scrolling on keyup, I need to make some combination with keydown and keyup.
Or maybe there is some simpler way?
Thanks,
Indris
Reply to this.
Vinod Pahuja at 14 Jul, 2008 02:20
wat a gr8 script
it makes my application dev easier

Thanks a lot
Reply to this.
Anonymous at 14 Jul, 2008 12:13
I must be a moron or something but this code absolutley does not work for me..

this is how i'm putting it in my site

<script type='text/javascript' src='shortcut.js'>

shortcut.add("Ctrl+Shift+A",function() {
alert("ADMIN PAGE!");
},{
'type':'keydown',
'propagate':true,
'target':document
});

</script>
Reply to this.
God Franciz at 08 Aug, 2008 06:48
Do as Dave Myron said:
change this: var character = String.fromCharCode(code)
into this: var character = String.fromCharCode(code).toLowerCase()
Reply to this.
Steve Lloyd at 18 Jul, 2008 01:36
I have been trying for a while to find a way of selecting all the images in a photo application with ctrl+A, rather than everything in the browser window. I have tried may recipes but none worked. However, your code works a treat. Thanks very much.
Reply to this.
Peter Krausche at 19 Jul, 2008 06:27
I've been using your script in a project of mine and in most cases it works fine. Thx a bunch!

I am having a few problems though.

First, I'm trying to install a listener for the ENTER key on an input element. Thing is, I already have an onKeyUp defined for the element and an onSubmit for the form (activated by a hidden submit button). Now, when I define an ENTER listener with your shortcut script, the onSubmit of the form no longer works when I press ENTER.

Another problem is that of different keyboard layouts when the subject of shortcuts is viewed from an international perspective. For instance, I live in the German-speaking part of Switzerland, and some of the effects I've stumbled across using your script with various shortcuts are...uh, well, let me say, quite interesting.

Any ideas?

Of course, if you need any further information, just let me know... ;-)
Reply to this.
Anonymous at 19 Jul, 2008 12:16
hellloo..
I have problem.

Great Script, thanks for sharing.
i want to ask you one qustion ?
when i try to add a shortcut(Ctrl+S) it's work but after calling my function the save dialog appear how i can remove this dialog?


Reply to this.
Anonymous at 21 Jul, 2008 05:11
Please is anywhere some example to simple use this js library? How to I init this script on a page?
Reply to this.
eContento at 22 Jul, 2008 11:58
Hello,

I have a big problem in Firefox

Ctrl+F4 is not stop with e.stopPropagation() and e.preventDefault().

How can I avoid this bubble?
Reply to this.
Anonymous at 29 Jul, 2008 09:46
Hi i am using IE 7.0.6000
and even on the website I cant get any example to work
which uses Modifier+Letter
it works fine with Modifier+Number
like
Ctrl+2 works
but
Ctrl+S doesnt work
Ctrl+a or Ctrl+A doesnt work

the default example after executing the code which was "Ctrl+Shift+X" did not work

and nor did these things worked on my other computer which is running IE 6.0.2900
Reply to this.
Anonymous at 29 Jul, 2008 09:49
Hi, there is a problem
when I use shortcuts with
Modifier+Letter
they dont work
Ctrl+S Ctrl+B Ctrl+s Ctrl+b etc wont work

even the default Ctrl+Shift+X did not work nor did the Ctrl+A worked
which was in your site demo. It did select everything but the function wasnt called.

Modifier+Number works though.
like Ctrl+2 works or Ctrl+Shift+2 works

I tried both on IE 7.0.6000 (Vista) and IE 6.0.2900 (XP)
Reply to this.
Anonymous at 29 Jul, 2008 09:52
adding on to the previous post they didnt work on Netscape version 8.1 (based on firefox) also.
I dont understand since i am testing it on 2 different computers so it shouldnt be the computers
and it shouldnt be the os
since one is running Vista and the other is running XP
Reply to this.
Mac at 03 Aug, 2008 07:30
Magnificent code, very nicely done.
Reply to this.
Sami at 07 Aug, 2008 03:49
Hiya, what a great piece of work this is. Keep on updating mate. One quick question, I managed to the script working just fine on F5, Ctrl, Ctrl+2, however when the script did not catch the Ctrl+B or Ctrl+R. Am I on the right track? here is my piece of code:

<script language="javascript" type="text/javascript" src="{$smarty.const.JS_DIR}shortcut.js">

</script>
<script language="JavaScript">
function init() {
shortcut.add("Ctrl+R", function() {
alert("ctrl+R");
});
shortcut.add("F5", function() {
alert("F5");
});

}
</script>
<body onLoad="JavaScript:init();">
</body>

Remember that the F5 works, meaning that all the links are working just fine, it is just I cant get the Ctrl+R and Ctrl+B work. Any clue guys? Thanks alot. What a great work this is.
Reply to this.
Sami at 07 Aug, 2008 04:36
Hi, i just found out that, using both my Safari on Mac G5 and IE7 on my vaio, Ctrl plus any alphabets just doesnt work. However ctrl plus any special character or number does work. Anyone knows why this is happening? Is it because the alphabets are not defined in the shortcut.js?
Reply to this.
Bijoy at 20 Mar, 2009 12:29
Try using this..

//Find Which key is pressed
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
character=character.toLowerCase(); // Added this line

I have converted the key character to Lowercase... and I am trapping keys onkeydown. onkeypress donot work on IE6.

Above change worked fine on IE6, FF3 and Safari. This patch was unsuccesful on IE7. Still figuring out a way out. Tested with "SHIFT+CTRL+C".
Reply to this.
Anonymous at 13 Aug, 2008 10:40
Hi Binny,
I'm new to this javascript / html stuff so forgive me if I'm asking a stupid question. I have numerous buttons on my screen that perform different tasks. My users have requested that I attach Fkeys to each of these buttons. (They prefer to use an f key rather than a mouse click). I'm trying to set up F10 to execute a program IF the user entries on the screen are valid. I have a function called validateform that checks for valid entries. How would I incorporate your shortcut.add code to do this? Here is my current code but I can't get function validateform to work.

Here is a portion of my form:
<FORM name="formx" METHOD="POST" ACTION="/VFI/BIN/astart.EXE" onsubmit="return validateform(this);">

<INPUT class="mybutton" TYPE=submit title="F10" value="Update" onclick="formx.buttont.value='UPDATE';">

If the users use the mouse and click the button, the form is validated but my shortcut below
is not validating the form (Buttont must have a value of update).

shortcut.add("F10",function() {
validateform
formx.buttont.value='UPDATE';
formx.submit();
});

Thanks for the work that you have done. My other f keys using shortcut are working fine.
Reply to this.
Anoop Pillai at 14 Aug, 2008 06:23
the current script doesn't works for any character combination (Alt+a/CTRL+m).
This can be solved by adding the beliow line:
character=character.toLowerCase();

after the line:
var character = String.fromCharCode(code);
Reply to this.
Richard at 30 Sep, 2008 03:54
Thanks for your little tip.
Actually this script is very useful for me.
Reply to this.
Anonymous at 17 Aug, 2008 07:43
Hi,

Thanks for such great script, very nice indeed.

I used it in a page I am developing (not online yet) and it worked fine, however, another short script in the page for tooltips (called qtip from http://qrayg.com) which was working fine up till then suddenly stopped. Can you please help me? I´m stumped, I tried to figure out what the incompatibility is between the two but couldn´t.

Thanks in advance,

Daniel
Reply to this.
Tien Dung at 18 Aug, 2008 08:08
Hi,

I've refactored the JavaScript code to make it cleaner and easier to read & maintain:

Please check it out at:
github.com/tiendung/javascript-utils/tree/master/shortcut.js
Reply to this.
Anonymous at 28 Aug, 2008 03:50
adding on to the previous post they didnt work on Netscape version 8.1 (based on firefox) also.
I dont understand since i am testing it on 2 different computers so it shouldnt be the computers
and it shouldnt be the os
since one is running Vista and the other is running XP
Reply to this.
Anonymous at 09 Sep, 2008 01:53
Thanks for such great script, very nice indeed.

I used it in a page I am developing (not online yet) and it worked fine, however, another short script in the page for tooltips (called qtip from http://qrayg.com) which was working fine up till then suddenly stopped. Can you please help me? I´m stumped, I tried to figure out what the incompatibility is between the two but couldn´t.
Reply to this.
Zotheca at 10 Sep, 2008 05:15
This is a nice little Javascript library. I have added a clear function to the shortcut object that will clear all added shortcuts. This is very helpful when using the shortcut script on a AJAX based website.




function removeShortcut(combination) {
var binding = bindings[combination];

delete bindings[combination];

if( !binding ) return;

var type = binding.event;
var ele = binding.target;
var callback = binding.callback;

alert( ele.removeEventListener + " - " + ele.detachEvent );

if (ele.removeEventListener)
ele.removeEventListener(type, callback, false);
else if (ele.detachEvent)
ele.detachEvent('on'+type, callback);
else
ele['on'+type] = false;
}


// ....

//Remove the shortcut - just specify the shortcut and I will remove the binding
remove: function(combination) {
combination = combination.toLowerCase();
removeShortcut(combination);
},

//Remove all define shortcuts
clear: function() {
for (var combination in bindings) {
removeShortcut(combination);
}
}
Reply to this.
Srinivas at 23 Sep, 2008 03:51
hi is there any way to capture the actions performed on the menus of a browser window. Eg: Saving a page by clicking File-> Save Page As.

Please reply as soon as possible.
Reply to this.
Binny V A at 23 Sep, 2008 08:23
I don't think that can be done.
Reply to this.
Anonymous at 26 Sep, 2008 12:36
Thanks for the script. I was in desperate need of implementting of shortcut keys to my project.
Im not able to catch the shortcut events along with Alt and Cntrl modifiers along with Alphabets(a-z or A-Z)

In using the shortcut.js below the CODE section.

Please help me out..
Im using the below code.

shortcut.add("Ctrl+D",function() {
alert("Saved!");
});

shortcut.add("Alt+L",function()
{alert("Help Me!");});
Reply to this.
Anonymous at 25 Sep, 2008 02:28
adding on to the previous post they didnt work on Netscape version 8.1 (based on firefox) also.
I dont understand since i am testing it on 2 different computers so it shouldnt be the computers
and it shouldnt be the os
since one is running Vista and the other is running XP
Reply to this.
Anonymous at 06 Oct, 2008 11:28
Nice work on the shortcuts script. I am having a little difficulty getting it to work with letter combinations such as Ctrl+s. I am using XP with IE 6 sp2. Here is the snippet of code that does work:

function init() {

//Calls the Search screen.
shortcut.add("Ctrl+1", function(){
alert("You have pressed CTRL+1");
displayKey();
return;
},{
'type':'keydown',
'propagate':false,
'target':document
}
);
}

This does not work. Nothing happens when the key combination is pressed:
Nice work on the shortcuts script. I am having a little difficulty getting it to work with letter combinations such as Ctrl+s. I am using XP with IE 6 sp2. Here is the snippet of code that does work:

function init() {

//Calls the Search screen.
shortcut.add("Ctrl+s", function(){
alert("You have pressed CTRL+s");
displayKey();
return;
},{
'type':'keydown',
'propagate':false,
'target':document
}
);
}

Any help would be appreciated.

Thanks In Advance,

b
Reply to this.
Anonymous at 07 Oct, 2008 03:31
Hi brother----------
Excellent work that gives a browser application the potential of windows application ---
But i am not able to figure out where the script is creating the problem --- I m able to create numeric shortcuts like Ctrl+ etc but not able to create shortcuts with alphabetic keys --- even i tried combinations with arroww keys and they also worked but help me in creating alphabetic shortcuts -- i m using the IE 6 and also checked in google chrome--- waiting for the fast reply---
Jatin
Reply to this.
Jonathan Tang at 16 Oct, 2008 06:53
I've written a library that does basically the opposite of shortcut.js. Instead of taking a key description string and binding an event handler, it takes a keyboard event and outputs a string suitable for shortcut.js event binding:

jonathan.tang.name/code/js_keycode

It may be useful if you want to allow users to specify their own hotkeys with a keypress, and save those keys for later event binding.
Reply to this.
Binny V A at 16 Oct, 2008 09:52
That's a really nice tool - makes it easier for people to my library. Thanks.
Reply to this.
Stephen Caine at 18 Oct, 2008 11:17
I am looking for the proper way to trigger the clear cache event (for Safari) when a user clicks the submits button. Currently this is a menu item, but I need for it to occur automatically. I have looked up the key equivalents for this (Alt+E+69), but I am not sure how to code this properly. Do you have a suggestion?

Thanks
Reply to this.
Aman Aggarwal at 19 Oct, 2008 07:20
All the scripts given by you are really very nice..
Great Job..
But guys is there any key to block property key of keyboard..i.e from where we normally work as right click of mouse.
Reply to this.
Anonymous at 22 Oct, 2008 06:44
Hi Thanks it is working but if i am having iframe it is notworking.

<script type ="text/javascript" src ="shortcut.js"> </script>
<script type ="text/javascript" >
shortcut.add("alt+f3", function() {
alert("Called");
});
</script>

<asp:Button ID="Button1" runat="server" Text="Button" />
how to fire the button event "click" if i use the "shift+p" or "shift+N+P"

Thanks.
Reply to this.
Anonymous at 27 Oct, 2008 05:57
All the shortcuts are working .But the problem is i am not able to get the shortcut keys working in <IFRAME> .If the iframe is having the focus. All other controls are working perfectly.
Reply to this.
naugtur at 24 Nov, 2008 05:26
I had a similiar problem, but this one is easy to fix. Just copy-paste your shortcut defining code to the document inside the iframe (<iframe src=empty.html > and in the head of empty.html U put the code). To refer to the upper document use window.parent


Everything works like a charm unless U use Opera...
Reply to this.
Neil Trigger at 18 Jan, 2009 02:59
try using <div> tags instead. you can set the style="" to include borders and overflow commands to act the same as an iframe and load content using javascript
Reply to this.
naugtur at 24 Mar, 2009 01:04
Impossible - I need iframe for this editor.
Reply to this.
naugtur at 24 Mar, 2009 02:03
problem SOLVED!! [at last]

1. when wanting to use shortcuts in iframe make it have src=empty.html and put a function bindthemall() {//make your shortcuts here} in the head.
2. for FF - call the function in the empty.html as onload or on DOM ready function
3. for opera - call the function from the parent like this: document.iftamename.contentWindow.bindthemall() whenever you change designmode. (Opera loses keybindings when setting designmode on)

and it works!
Reply to this.
Parthibhan at 31 Oct, 2008 11:52
I have added the shortcut for Ctrl+Q .But If i am pressing Ctrl + F2 , the 'Hi' alert is coming .
Please advise.

shortcut.add
('Ctrl+Q', function()
{
alert('Hi');
return;
}
,
{
'type':'keypress',
'propagate':false,
'target':document
}
);
Reply to this.
Parthibhan at 31 Oct, 2008 11:54
I am using Mozilla Firefox .
Reply to this.
Saeed at 02 Nov, 2008 07:32
Thanks for your comprehensive this Handling Keyboard shortcut script.
Reply to this.
Diego Pires at 05 Nov, 2008 08:15
Cancel propagate doesn't work on IE 7?
Reply to this.
Helder Silva at 06 Nov, 2008 05:55
I think i found a bug :\ when i use the following piece of code on my aplication:

shortcut.add("F5",function(){
alert('Operation not permited');
return false;
}, {'type':'keypress'});

When i press the F5 everything goes as planned, but the problem is that when i press the "t" key the script run as if i pressed the F5 :\

If i remove the type option it functions normaly.

Sory for my bad english and thanks for this script. :)
Reply to this.
Khoa Nguyen at 19 Nov, 2008 02:00
Nice work, but some cases don't work on FF3.
Reply to this.
Arpan Dhandhania at 22 Nov, 2008 11:55
Hi,
I am using keyboard shortcuts to control the entire web application that I am working on. More specifically, I am using the Enter key to start editing the entry that is selected. Hitting enter again saves the text typed in the text area. I am over ridding the enter property in the text area. So hitting enter doesn't put a carriage return in the text area.

All this is working fine. However, I have text box that is used to leave comments. I want the Enter key to work normally in there. Is there a way for me to tell the script that you don't do anything in this textbox?

THe other alternative that I can think of is to disable shortcuts onFocus of the comments box and then re-enable them onBlur. But I am not totally happy with this solution.

Someone, please give me a better way to solve my problem.

Thanks,
Arpan D.
Reply to this.
naugtur at 24 Nov, 2008 05:17
as written in the page:
target - DOM Node
The element that should be watched for the keyboard event. Default : document

If U provide a good target it should react only on target object.

So just wrap all the enter-saved object in a div or something and try setting shortcut on this.


PS. Help with getting shortcuts in opera designmode iframe would be a good thing to give in return :P
Reply to this.
Arpan Dhandhania at 01 Dec, 2008 01:03
Hi,
I have used this library in my web app. I am extensively using the ALT key shortcuts. On Google Chrome, the ALT ket shortcuts are not working. Bsically the ALT key isnt getting caught. Any way to get it to work? Is there an update to this library? I love this library.

Thanks in advance,
Arpan.
Reply to this.
Srini at 06 Dec, 2008 01:04
hey does it work with chrome?
Reply to this.
Anonymous at 06 Dec, 2008 05:24
Hi,
I am using keyboard shortcuts to control the entire web application that I am working on. More specifically, I am using the Enter key to start editing the entry that is selected. Hitting enter again saves the text typed in the text area. I am over ridding the enter property in the text area. So hitting enter doesn't put a carriage return in the text area.

All this is working fine. However, I have text box that is used to leave comments. I want the Enter key to work normally in there. Is there a way for me to tell the script that you don't do anything in this textbox?

THe other alternative that I can think of is to disable shortcuts onFocus of the comments box and then re-enable them onBlur. But I am not totally happy with this solution.

Someone, please give me a better way to solve my problem.

Thanks,
Arpan D.
Reply to this.
Anonymous at 13 Dec, 2008 12:55
Would it be possible to use a wildcard % key board action ? like press any key to continue
Reply to this.
Anonymous at 21 Dec, 2008 07:59
popup blockers and browser settings block automated popups or window.open scripts

Unless an actual mouse click is instigated for a given URL, we are warned with a message across the top of the page/

Is their any known function we could use to trigger a new window, using the shortcut function to activate it ?
Reply to this.
Anonymous at 21 Dec, 2008 09:10
Sorry I should have included ctrl+t but I dont know how to assign a url
Reply to this.
gautam at 25 Dec, 2008 04:24
Please Help me i have one php page which is reload automatically but now i want this page upload automatically when any event not occur on the screen then and then only this page upload automatically but if we are working on this page like mouse move or mouse click or any key press on key boar then auto reload function is not working. So when no event on screen then reload or working on screen then no refresh automatically



Thanks,
Gautam
Reply to this.
nguyenviet at 02 Jan, 2009 12:05
hm....I use follow example but it's run or active. Someone do it, say with me, thanks.
Reply to this.
Parthibhan at 07 Jan, 2009 06:52
Hi,
I have added the shortcut for Ctrl+S .But If i am pressing Ctrl+F4 , the 'Hi' alert is coming .
If i use 'keydown' in 'type', the save dialog box will come while pressing Ctrl+S .
Please advise.

shortcut.add
('Ctrl+S', function()
{
alert('Hi');
return;
}
,
{
'type':'keypress',
'propagate':false,
'target':document
}
);
Reply to this.
Daniel R. at 09 Jan, 2009 02:53
This seems like fun, but your code throws over 15 Javascript alerts when it's executed. Just check it out using the Web Developer extension in Firefox. And I can't even type the number '1' in this textarea without using the numpad (the other '1' key above the 'Tab' and "Q' keys is disabled, thanks to the script).
Reply to this.
manhnghi at 11 Jan, 2009 08:23
It's very good job, i like your script so much
Reply to this.
Kaido at 11 Jan, 2009 08:26
Can you help me, when press F2 call "function {Respone.Redirect("default.aspx")}"
Reply to this.
Anonymous at 06 Feb, 2009 06:53
Response.Redirect is a server side method. I found this using Google: support.microsoft.com/kb/208649

Maybe that will help you do redirection on the client side.
Reply to this.
islami at 13 Jan, 2009 03:36
Perhaps consider some other language if you require it; maybe even a little applet?
Reply to this.
Jamp Mark at 17 Jan, 2009 08:38
this is great piece of work.
now i can hook a function on shift-tab to traverse input fields backwards.

shortcut.add("Shift+Tab",function() {
alert("Hi there!");
});

i will use this for navigating across fields.

thanks for sharing.
Reply to this.
Anonymous at 26 Jan, 2009 05:54
There is a case-sensitivity bug.

var character = String.fromCharCode(code)
Change to this.
var character = String.fromCharCode(code).toLowerCase()
Reply to this.
Anonymous at 07 Feb, 2009 12:01
Hi! This code is great! I have a question about using it, though. What are the issues regarding license for this? I mean, do I have to do anything special to use it legally? I'm a little confused about BSD licensing. Thanks
Reply to this.
Dan G. Switzer, II at 10 Feb, 2009 12:39
For users looking to use this with Chrome, there is a bug with Chrome that causes the e.metaKey event to return true when the ALT key is pressed:

code.google.com/p/chromium/issues/detail?id=2215

This causes any keyboard shortcuts with the ALT key to fail in Chrome.

You can rectify this by commenting out the following lines:

if(e.metaKey) modifiers.meta.pressed = true;

and

} else if(k == 'meta') {
kp++;
modifiers.meta.wanted = true;

Now obviously, this breaks things for the Mac if you want to check for the meta key. If you need the META keyboard shortcut, you could change the following line:

if(e.metaKey) modifiers.meta.pressed = true;

To something like:

if(e.metaKey && navigator.userAgent.toLowerCase().indexOf("chrome") == -1) modifiers.meta.pressed = true;

This would ignore the META key event in Chrome. Hopefully Google will resolve this bug sometime soon.
Reply to this.
subscribeid at 14 Feb, 2009 09:20
Hello,
can any one give me full code with shortcut.js, im new to JS and need to learn.
Reply to this.
subscribeid at 14 Feb, 2009 11:25
Hello
Is there any chances of openening a new window using shortcut.add(). if yes please let me know.
Reply to this.
Anonymous at 15 Feb, 2009 07:02
shortcut.add('key',function(){window.open('http://www.someUrl.com')});
Reply to this.
Anonymous at 17 Feb, 2009 04:21
I'm presuming this is the revised BSD license, but I would just like to make sure. I'm hoping to deploy it with some GPL code and I don't want to get caught up with attribution clause. Is this the new or old BSD license?
Reply to this.
Anonymous at 24 Feb, 2009 08:57
This script is working great but I wonder if anybody has the same these problems as I am:

- it work with numbers only, for example:
Ctrl+2: works
Ctrl+T: does not work
- If I specify any values for the third argument (optional), the
shortcut will not work, e.g:

shortcut.add("Ctrl+2", function() {alert('test');} : Works

shortcut.add("Ctrl+2", function() {alert('test');},
{
'type':'keydown',
'propagate':false
} : does not work
Any idea?
Reply to this.
Joe Giunta at 19 Mar, 2009 08:40
I am having the same problem. Hitting a number will fire my event, but hitting an Alpha character (with or without a modifier) will NOT fire my function. Help Please.

I am using IE7.
Reply to this.
Joe Giunta at 19 Mar, 2009 10:44
Ok a couple of hours later and I figured this out (I think).

** GOT IT WORKING **

First off the event needs to be "keydown" for my IE7 Master / Content page to catch the Ctrl key. Otherwise the functions in Shortcut.js won't even bother to fire.

--> shortcut.add("Ctrl+s", function() {imgSave_Click();}, {'type':'keydown','propagate':false,'target':document});
And yes for what ever reason I need the option parameters included in this line.

The next item was in ShortCut js at approx line #46 I need to make the character variable lower case:
--> var character = String.fromCharCode(code).toLowerCase();

Once those two changes were made, presto things started to work. Hope someone out there finds this useful, and saves them about 2-3 hours of work :-)

Reply to this.
Bijoy at 20 Mar, 2009 12:38
Hi Joe Giunta,

well... I think I didnot save my 2-3 hours and ended up finding the same solution... But, It still doesn't work on IE8 [Emulated as IE7] and IE7. I am trying.. SHIFT+CTRL+C.

Any idea on this... bro?
Reply to this.
Fanch at 27 Feb, 2009 06:50
Thanks for your script, it is very helpful.
Idem, on your site when i test with letters, it does not work. But it works fine with numbers.
But it works fine with options.

Please let me know for new version.
BR
Reply to this.
Fanch at 02 Mar, 2009 05:32
I found the bug,
It lacks a toLowerCase l46

var character = String.fromCharCode(code).toLowerCase();

Hope it helps
Reply to this.
Anonymous at 10 Mar, 2009 05:32
Hello,
Your code is very helpful for me. But i have a problem, (ie) i load a html page inside a iframe, when the cursor is in the iframe>text field, it did not capture any keyboard shortcuts. Is there any ways to do this? thanks in advance.

Regards,
Ananthavel.S
Reply to this.
Anony at 11 Mar, 2009 02:48
Because iframes are pages from another source, you would need to place the js code on the iframe page been displayed
Reply to this.
Anonymous at 11 Mar, 2009 11:01
Hello,
I have placed the JS code both in Parent window and All Child windows(ie pages loading in IFRAME) but nothing works. Also i tried to get from window.getElementById('IFRAMEID'). But it does not help. Kindly let me know for any solutions.
shortcut.add("Shift+F5",function() {
alert("HGello");
},{
'type':'keydown',
'disable_in_input':false,
'target':window.child/parent
});
Reply to this.
naugtur at 24 Mar, 2009 02:04
read my reply up there. already solved
Reply to this.
AD at 16 Mar, 2009 04:30
Thank you so much for your code. I finally got my way around to get on keypress event working in all browsers. Thank you so much for your work.
Reply to this.
Aditya at 17 Mar, 2009 03:35
Wow , i made my web base application like a destop most of command control using a keyboard .

Thank you so much for your work

Regards
Aditya
Reply to this.
Johnny at 18 Mar, 2009 05:04
Well, I implemented your shortcut.add()

But I'm getting one javascript error in the following line

//Find Which key is pressed
if (e.keyCode) code = e.keyCode; (error in code = e.keyCode condition)

So I commented the condition and directly using e.keyCode as follows
var character = String.fromCharCode(e.keyCode).toLowerCase();

Now it's working fine...will it create any problem...reply me at the earliest.

Thanks,
Johnny
Reply to this.
Sankar at 18 Mar, 2009 10:44
I too faced the same problem....

If you have any control name in jsp as code then the line

if (e.keyCode) code = e.keyCode; (error in code = e.keyCode condition)

will throw js error...

Try to avoid using var name as code in js also...
Reply to this.
forum at 23 Mar, 2009 10:21
Thank you so much for your code.
Reply to this.
Anonymous at 23 Mar, 2009 05:17
The shortcut effects are wonderful. Thank you for putting together this code.

However, I wonder if there is a way to clean up all the syntax warnings reported by www.jslint.com based on your code. It will help clean up the warnings generated in the Microsoft VS2008 IDE, when using your Javascript code, I suppose.

Thank you,


Reply to this.
Anonymous at 24 Mar, 2009 06:23
yes it works in both IE and Mozilla using Html. But the thing is. When i use the script in my Web application. It works in Mozilla only not in IE... can you give me an idea on how to work it in IE. By the way my IE is version 7
Reply to this.
gopu at 25 Mar, 2009 06:46
Thank you for the amazing piece of code
Reply to this.
janakrai at 03 Apr, 2009 05:27
i am used your code it is Realy gr8, it is very help full me. i am intigrate in my php application,
Reply to this.
NizamDeen at 09 Apr, 2009 09:36
Hi Dear
Really very fantastic script.....

but i need to restrict for mouse pointer key which is located between Ctrl and Alt ... can u tell me suggestion ...
Reply to this.
izlesene at 18 Apr, 2009 02:24
I am using Mozilla Firefox
Reply to this.
Reiatsu at 23 Apr, 2009 04:21
Thanks Binny. One word, FANTASTIC. Your are the man. Thank you very much.
Reply to this.
LockeVN at 26 Apr, 2009 09:04
Thanks, I used for my site tiutit.com
Reply to this.
Benson Wong at 02 May, 2009 09:22
I made a small modification to the script, changing line 40 to

if(element.tagName == 'INPUT' || element.tagName == 'BUTTON' || element.tagName == 'TEXTAREA')

That way the script won't fire if focus is on a <button> as well.
Reply to this.
Anonymous at 04 May, 2009 12:36
i have problems sing the f5 key in I.E 7. The f5 key on pressed reloads the page instead of calling my function. please help...
Reply to this.
Anonymous at 11 May, 2009 08:16
Thank you this is fantastic. I am wondering if its possible to define multiple combinations for example Ctrl+K+A.
Reply to this.
siennd at 16 May, 2009 08:50
hats off to Binny V A. Great job man. I owe you one.
Reply to this.
Anonymous at 18 May, 2009 03:24
hats off to Binny V A. Great job man. I owe you one.
Reply to this.
Anonymous at 22 May, 2009 02:31
Well, I implemented your shortcut.add()

But I'm getting one javascript error in the following line

//Find Which key is pressed
if (e.keyCode) code = e.keyCode; (error in code = e.keyCode condition)

So I commented the condition and directly using e.keyCode as follows
var character = String.fromCharCode(e.keyCode).toLowerCase();

Now it's working fine...will it create any problem...reply me at the earliest.

Thanks,
Savas
Reply to this.
Nick at 25 May, 2009 11:31
With Firefox 3.0.10 under Linux, String.fromCharCode returns "m" when the minus key ("-") is pressed, so I've added this near line 50 to make things work for me :

if(code == 109) character="-";
Reply to this.
Anonymous at 25 May, 2009 11:29
Hi there,
I am trying to add shortcut for Alt+Home- that should take me to the main page of my site,
But instead it takes me to the home page set on my browser.
Surprisingly, when i put an alert in my function, it starts working as expected.
Any help would be appreciated.
Regards

Code
shortcut.add("Alt+Home",function() {

document.forms[0].action="My URL";
document.forms[0].submit();
},{
'propagate':false
});
Reply to this.
Anonymous at 26 May, 2009 04:48
In the text area above, execute:
shortcut.add("c",function() {
alert("Hi there!");
}); Thankyou weriy code
Reply to this.
KM Websol at 27 May, 2009 04:29
Hello Sir,
Nice and very useful for everyone.
But little problem i have,
My page has IFRAME in which i am showing pdf...
In that case to use shortcut, i have to click somewhere on document, then only it works.
Any suggestions?

Paresh
Reply to this.
murat at 28 May, 2009 11:30
Dude, this is great... can you add a download source code and all portion in this page?...
Reply to this.
tatil at 07 Jun, 2009 01:44
But little problem i have,
My page has IFRAME in which i am showing pdf...
In that case to use shortcut, i have to click somewhere on document, then only it works...
Reply to this.
ikinci el iş makinaları at 07 Jun, 2009 01:45
ou add a download source code and all..
Reply to this.
Manoj babu at 08 Jun, 2009 06:52
Dear Binny

On load i am initiating the function, when i click ALT key first time, i am getting " Code is undefined" could u help me out
Reply to this.
ksteigerwald at 15 Jun, 2009 08:11
Very nice. Would I be able to create a short cut by holing down a numeric key and clicking on a selected area? So 3 + click ?
Reply to this.
Joost at 16 Jun, 2009 10:39
It seems 'propagate':false doesn't work in Opera
Reply to this.
Anonymous at 21 Jun, 2009 07:43
This is exact, "propagate: false" doesn't work on Opera.
If you could fix this it would be really helpful.

Thanks a lot for this script, it is really nice.
Reply to this.
Sohbet at 20 Jun, 2009 09:27
I am using Mozilla Firefox
Reply to this.
chat at 20 Jun, 2009 09:28
I am using Mozilla Firefox
Reply to this.
Sohbet kanalları at 20 Jun, 2009 09:30
i am used your code it is Realy gr8, it is very help full me...
Reply to this.
sohbet at 20 Jun, 2009 09:33
i am using Mozilla Firefox
Reply to this.
chat at 20 Jun, 2009 09:38
thank you :D
Reply to this.
Sohbet at 22 Jun, 2009 11:32
thank you :)
Reply to this.
Sohbet odaları at 22 Jun, 2009 11:33
thanks
Reply to this.
Sohbet kanalları at 22 Jun, 2009 11:33
thanks
Reply to this.
Anonymous at 27 Jun, 2009 02:44
Thanks so much! I'm getting a Dell Studio 1555 which has a keyboard where you need to refresh with Fn + F5. So I made a userscript with this to refresh with F5. Me happy =D
Reply to this.
sohbet at 27 Jun, 2009 05:31
hi good than you i have to click somewhere on document, then only it works...
Reply to this.
sohbet at 27 Jun, 2009 02:52

thank you very much but i have seen this subject somewhere before also it is not explained well like that.

Reply to this.
Anonymous at 29 Jun, 2009 10:17
Great work. Thanks for sharing
Reply to this.
oteller at 01 Jul, 2009 01:21
I love your scripts. They are very easy to use, they work perfect and the update with the disabling in input/textarea is the last thing I missed.
Reply to this.
haberler at 01 Jul, 2009 01:21
thank you very much but i have seen this subject somewhere before also it is not explained well like that.
Reply to this.
tatil hotel at 01 Jul, 2009 01:22
thank you very much but i have seen this subject somewhere before also it is not explained well like that.
Reply to this.
konteyner at 02 Jul, 2009 01:10
I love your scripts. They are konteyner very easy to use, they work perfect and the update with the disabling in input/textarea is the last thing I missed.
Reply to this.
Comment

Please dont enter you comments in this form - this is a fake form to confuse spamming bots. The next form is the real one.




Comment




Comment Formating : HTML tags a, strong, em, b, i, code, pre, p and br allowed. Other tags will be shown as code(< will become &lt;). Urls, Line breaks will be auto-formated.