Skip to main content

Bug Tracker

Side navigation

#3368 closed enhancement (fixed)

Opened September 12, 2008 07:55PM UTC

Closed September 27, 2011 01:28AM UTC

Last modified March 08, 2012 05:11PM UTC

event.metaKey should be assigned to event.ctrlKey on Non-Mac only

Reported by: tzury Owned by: dmethvin
Priority: low Milestone: 1.7
Component: event Version: 1.4.4
Keywords: needsreview,1.7-discuss Cc:
Blocked by: Blocking:
Description

at jquery.js | version 1.2.6 | line 2150

code:

// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for

Macs)

if ( !event.metaKey && event.ctrlKey )

event.metaKey = event.ctrlKey;

This is causing a buggy behavior in the following scenario:

A user wish to bind ctrl+x to function-A and command+x to function-B

When ctrl+x were pressed, event.metaKey is true as well as

event.ctrlKey so function-B is called even though only function-A

should be triggered.

The the would obviously be to add additional check for Mac or non Mac

operating system, something like:

if ( !event.metaKey && event.ctrlKey && !(/Mac

OS/.test(navigator.userAgent))

event.metaKey = event.ctrlKey;

Attachments (0)
Change History (24)

Changed September 12, 2008 10:41PM UTC by flesler comment:1

owner: brandonflesler
status: newassigned

Changed December 01, 2009 11:07PM UTC by yehuda comment:2

resolution: → invalid
status: assignedclosed

The purpose of event.metaKey is to provide a way of binding functionality to "user's native meta key" + "other key". For instance, meta+b could be used to trigger a "bold" mode. On OSX, this would be command+b, but on Windows, it would be ctrl-b.

Changed January 30, 2010 10:08PM UTC by babyman comment:3

resolution: invalid
status: closedreopened

Leaving all philosophy aside the Apple keyboard has a command (meta) key AND a control key. It is possible on a Mac to press the Control key WITHOUT pressing the Command key.

Therefore on a Mac meta != control it is simply not true regardless "the purpose of event.meta".

Even the author of the code indicated in their comment that this was intended for PC's only, they simple forgot to filter out Macs:

// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)

Changed January 31, 2010 01:55AM UTC by babyman comment:4

This seems like it might be a pretty decent workaround for those that are experiencing this issue, instead of:

var cmd = event.metaKey;

use:

var cmd = event.originalEvent.metaKey ? event.originalEvent.metaKey : false;

This means that cmd will be true only when the original event metaKey value was true, in all other cases it will be false even if the control key has been pressed (which seems like reasonable behaviour).

I'm new at this so feedback welcome ;)

Changed November 18, 2010 01:23AM UTC by snover comment:5

keywords: → needsreview
milestone: 1.3
priority: majorlow
status: reopenedopen
version: 1.2.61.4.4

I think it would make sense to create a separate cmdKey property so people can use metaKey as an “either ctrl or cmd depending upon platform” key, and still retrieve the value of the command key explicitly if they need to.

Changed March 17, 2011 03:51PM UTC by jquery@jp.payne-family.org comment:6

Well this three year old bug is a mess. Clearly it should be possible to tell the difference between a control and meta key, since the browser can trap any key it wants.

Hopefully the original event is unadulterated at this point so we can do the right thing.

Changed March 31, 2011 05:41PM UTC by dmethvin comment:7

Yes, event.originalEvent is there if you would like to read its tea leaves in a different way. I like snover's idea of a separate cmdKey property but given that there is a lot of code out there using the current properties I don't know if it would make things better or worse.

Changed March 31, 2011 06:24PM UTC by timmywil comment:8

So meta key here refers to the command key? The meta key as I understand it can be changed to alt/option on a Mac and then there is the start button key on pc keyboards. So I guess my question is can we guarantee consistency?

Changed April 17, 2011 05:26PM UTC by john comment:9

milestone: → 1.next
type: bugenhancement

I'm going to make this an enhancement and we can look at adding a new cmdKey in 1.7 (while removing the metaKey hack).

Changed May 22, 2011 07:27PM UTC by john comment:10

keywords: needsreviewneedsreview,1.7-discuss

Nominating ticket for 1.7 discussion.

Changed May 22, 2011 09:56PM UTC by dmethvin comment:11

+0, I do not know enough to swing on this, but don't think existing code should be broken by a solution.

Changed May 22, 2011 10:32PM UTC by rwaldron comment:12

description: at jquery.js | version 1.2.6 | line 2150 \ \ code: \ \ // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for \ Macs) \ \ if ( !event.metaKey && event.ctrlKey ) \ event.metaKey = event.ctrlKey; \ \ This is causing a buggy behavior in the following scenario: \ A user wish to bind ctrl+x to function-A and command+x to function-B \ When ctrl+x were pressed, event.metaKey is true as well as \ event.ctrlKey so function-B is called even though only function-A \ should be triggered. \ \ The the would obviously be to add additional check for Mac or non Mac \ operating system, something like: \ \ if ( !event.metaKey && event.ctrlKey && !(/Mac \ OS/.test(navigator.userAgent)) \ event.metaKey = event.ctrlKey; at jquery.js | version 1.2.6 | line 2150 \ \ code:\ \ // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for\ Macs)\ \ if ( !event.metaKey && event.ctrlKey )\ event.metaKey = event.ctrlKey;\ \ This is causing a buggy behavior in the following scenario:\ A user wish to bind ctrl+x to function-A and command+x to function-B\ When ctrl+x were pressed, event.metaKey is true as well as\ event.ctrlKey so function-B is called even though only function-A\ should be triggered.\ \ The the would obviously be to add additional check for Mac or non Mac\ operating system, something like:\ \ if ( !event.metaKey && event.ctrlKey && !(/Mac\ OS/.test(navigator.userAgent))\ event.metaKey = event.ctrlKey;

+1,

Changed May 22, 2011 11:38PM UTC by jaubourg comment:13

+0, Seems booby trapped to me

Changed May 23, 2011 01:40AM UTC by ajpiano comment:14

+1, I like the adding of a cmdKey - let people actually test for what they're trying to test for.

Changed May 23, 2011 02:40AM UTC by timmywil comment:15

+0, metaKey works correctly as a proper indicator of pressing command (and it is still possible to differentiate between control and meta). This may be more a problem with the ctrlKey logic. http://jsfiddle.net/timmywil/wWrAR/

Changed May 23, 2011 05:33AM UTC by addyosmani comment:16

description: at jquery.js | version 1.2.6 | line 2150 \ \ code:\ \ // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for\ Macs)\ \ if ( !event.metaKey && event.ctrlKey )\ event.metaKey = event.ctrlKey;\ \ This is causing a buggy behavior in the following scenario:\ A user wish to bind ctrl+x to function-A and command+x to function-B\ When ctrl+x were pressed, event.metaKey is true as well as\ event.ctrlKey so function-B is called even though only function-A\ should be triggered.\ \ The the would obviously be to add additional check for Mac or non Mac\ operating system, something like:\ \ if ( !event.metaKey && event.ctrlKey && !(/Mac\ OS/.test(navigator.userAgent))\ event.metaKey = event.ctrlKey; at jquery.js | version 1.2.6 | line 2150 \ \ code: \ \ // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for \ Macs) \ \ if ( !event.metaKey && event.ctrlKey ) \ event.metaKey = event.ctrlKey; \ \ This is causing a buggy behavior in the following scenario: \ A user wish to bind ctrl+x to function-A and command+x to function-B \ When ctrl+x were pressed, event.metaKey is true as well as \ event.ctrlKey so function-B is called even though only function-A \ should be triggered. \ \ The the would obviously be to add additional check for Mac or non Mac \ operating system, something like: \ \ if ( !event.metaKey && event.ctrlKey && !(/Mac \ OS/.test(navigator.userAgent)) \ event.metaKey = event.ctrlKey;

+1,

Changed May 23, 2011 03:17PM UTC by danheberden comment:17

description: at jquery.js | version 1.2.6 | line 2150 \ \ code: \ \ // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for \ Macs) \ \ if ( !event.metaKey && event.ctrlKey ) \ event.metaKey = event.ctrlKey; \ \ This is causing a buggy behavior in the following scenario: \ A user wish to bind ctrl+x to function-A and command+x to function-B \ When ctrl+x were pressed, event.metaKey is true as well as \ event.ctrlKey so function-B is called even though only function-A \ should be triggered. \ \ The the would obviously be to add additional check for Mac or non Mac \ operating system, something like: \ \ if ( !event.metaKey && event.ctrlKey && !(/Mac \ OS/.test(navigator.userAgent)) \ event.metaKey = event.ctrlKey; at jquery.js | version 1.2.6 | line 2150 \ \ code:\ \ // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for\ Macs)\ \ if ( !event.metaKey && event.ctrlKey )\ event.metaKey = event.ctrlKey;\ \ This is causing a buggy behavior in the following scenario:\ A user wish to bind ctrl+x to function-A and command+x to function-B\ When ctrl+x were pressed, event.metaKey is true as well as\ event.ctrlKey so function-B is called even though only function-A\ should be triggered.\ \ The the would obviously be to add additional check for Mac or non Mac\ operating system, something like:\ \ if ( !event.metaKey && event.ctrlKey && !(/Mac\ OS/.test(navigator.userAgent))\ event.metaKey = event.ctrlKey;

+1

Changed June 03, 2011 01:05PM UTC by john comment:18

+1

Changed June 03, 2011 02:04PM UTC by scottgonzalez comment:19

+1

Changed June 04, 2011 10:14PM UTC by addyosmani comment:20

+1

Changed June 06, 2011 03:32PM UTC by jzaefferer comment:21

+1

Changed July 11, 2011 05:28PM UTC by ajpiano comment:22

description: at jquery.js | version 1.2.6 | line 2150 \ \ code:\ \ // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for\ Macs)\ \ if ( !event.metaKey && event.ctrlKey )\ event.metaKey = event.ctrlKey;\ \ This is causing a buggy behavior in the following scenario:\ A user wish to bind ctrl+x to function-A and command+x to function-B\ When ctrl+x were pressed, event.metaKey is true as well as\ event.ctrlKey so function-B is called even though only function-A\ should be triggered.\ \ The the would obviously be to add additional check for Mac or non Mac\ operating system, something like:\ \ if ( !event.metaKey && event.ctrlKey && !(/Mac\ OS/.test(navigator.userAgent))\ event.metaKey = event.ctrlKey; at jquery.js | version 1.2.6 | line 2150 \ \ code: \ \ // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for \ Macs) \ \ if ( !event.metaKey && event.ctrlKey ) \ event.metaKey = event.ctrlKey; \ \ This is causing a buggy behavior in the following scenario: \ A user wish to bind ctrl+x to function-A and command+x to function-B \ When ctrl+x were pressed, event.metaKey is true as well as \ event.ctrlKey so function-B is called even though only function-A \ should be triggered. \ \ The the would obviously be to add additional check for Mac or non Mac \ operating system, something like: \ \ if ( !event.metaKey && event.ctrlKey && !(/Mac \ OS/.test(navigator.userAgent)) \ event.metaKey = event.ctrlKey;
milestone: 1.next1.7

Changed September 23, 2011 02:49AM UTC by dmethvin comment:23

owner: fleslerdmethvin
status: openassigned

Let's see if we can get this closed for 1.7.

On Mac, this code should never be executed I assume; I don't have a Mac to test on. So let's move on to Windows.

On Firefox 6, Chrome 13, Opera 11.5, and IE9, metaKey and ctrlKey move in unison and both are Boolean, so the code isn't needed.

On IE6, IE7 and IE8, metaKey is undefined when the Ctrl key is pressed alone but true when pressed in unison with another key. I suspect this may be why the patch was put in originally. So if we check for typeof(e.metaKey==="undefined") rather than falsey it should handle this case.

Changed September 27, 2011 01:28AM UTC by dmethvin comment:24

resolution: → fixed
status: assignedclosed

Fixed along with #8789 refactor.