Detect Windows-like or Mac-like keyboard in Javascript

1.2k Views Asked by At

My web app has a feature where the user can hold Ctrl (Windows, ctrlKey) or Cmd (Mac, metaKey). I want to provide help text telling the user they can do this.

What's a reliable way to detect a Mac-like keyboard? Is navigator.platform.match(/mac/i) safe enough?

1

There are 1 best solutions below

0
Steve Bennett On

This seems to be reliable:

const isMac = navigator.userAgent.includes('Mac');