Ho do I capture ctrl + click on MacOS with d3js

I got a report that my script which should trigger on ctrl + click does not work on Mac.

Like shown in "Determine if Shift key is pressed during mousedown event" we can determine if modifier keys are pressed during a mouse click testing d3.event.shiftKey, d3.event.ctrlKey etc. The shift detection works everywhere but ctrl does not seem to work on MacOS.

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

d3.select(window).on("click", function() {
    if (d3.event.ctrlKey) {
        alert("Mouse + Ctrl pressed");
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>

I don't have a Mac but I tested the script above using BrowserStack with:

    <li>Mavericks with Safari 7.1, Firefox 54 and Chrome 60;</li> <li>Sierra with Safari 10.1, Firefox 54 and Chrome 60</li> </ul>

    It is not working with any of the browsers on Mac. It works fine on Windows and Linux though.

    What do I do wrong? Is the ctrl key some kind of a special key on Mac OSes (I suppose it is as Mac has also the 'command' key). Is using the ctrl + click discouraged for Mac OS compatibility?

    Edit: I found this one: "any way to detect ctrl + click in javascript for osx browsers? no jQuery". My questions still holds as using d3.js framework I would expect that there is a way to do this in a cross-browser compatible way using d3.event.


    You can check this in the following way:

    if (d3.event.ctrlKey || d3.event.metaKey) { alert("Mouse + Ctrl pressed (or command key for Mac users)"); }


  • Ace editor, how to turn on block selection without having to press alt
  • Rotating Images & Pixel Collision Detection
  • jQuery to switch to next field using barcode reader
  • SelectItem Method in spark Datagrid?
  • Javascript event, the parameter “e” , “event” or other
  • PHP strptime format bug?
  • How do I increase font size in RStudio Help pane?
  • R and RStudio don't display greek letters and other symbols - display squares instead
  • Android - How to generate touch event from javascript?
  • Asking for undo/redo events in html/javascript
  • Determine if Finder can be safely killed
  • How to realize with WinForms in C# something like an image with map areas in a homepage (at hooverin
  • Git Merge Adds New File Instead of Conflict Markers - CONFLICT (rename/add)
  • Prevent focus to URL bar with CTRL + L
  • Efficiently getting XML into Elasticsearch
  • Negating Regex PO BOX
  • Count New Lines in Text File
  • Plotting densities in R
  • How to use JavaScript to determine whether a file exists in a directory?
  • Functions in global context
  • Alert pop up with LWUIT
  • FileReader+canvas image loading problem
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • How to recover from a Spring Social ExpiredAuthorizationException
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • ILMerge & Keep Assembly Name
  • Convert array of 8 bytes to signed long in C++
  • Large data - storage and query
  • ORA-29908: missing primary invocation for ancillary operator
  • How to get next/previous record number?
  • WOWZA + RTMP + HTML5 Playback?
  • Compare two NSDates in iPhone
  • AngularJs get employee from factory
  • How do you join a server to an Active Directory (domain)?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How does Linux kernel interrupt the application?
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?