Do Macintosh computers use the same key codes as Windows? - javascript

I've written a game in Javascript on a Windows computer. I'm using onkeydown and onkeyup events to read key presses. My question is, do Macintosh computers use the same keyCodes as Windows? As I don't own a Mac I can't test if all the keys work the same way.

Short answer: Yes.
See https://www.w3.org/TR/uievents-code/ for a full list and comprehensive description.

Related

Finding out which keyboard generated a key event in javascript

Is there some way to determine which keyboard connected to a device sent a particular key event in JS? For example, a laptop with a USB keyboard will happily honour keypresses on both keyboards but I cannot seem to find a way for the browser to tell me which source a key event came from so I can filter based on that (e.g. for player 1/2 input filtering for a browser based game, keyboard vs. "virtual instrument" for a browser based composing tool, etc.)
I couldn't find anything in the key events specs on MDN that suggests this is possible, but I'll be more than happy to take on any creative hack that makes this work "despite" rather than "thanks to" the spec.
Someone did ask this question back in 2013, and while its answer suggests using the gamepad API as workaround, it's now 2018 and three years of changes to JS APIs means that this question is worth reasking, in order get an answer based on the current state of the browser.
I dont know if it is already possible, but if would try something like that, i would study the WebUSB Api:
https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web
https://wicg.github.io/webusb/
Not so easy, but seems possible
It's not possible at present.
WebUSB won't allow access to HID devices, and WebHID won't allow access to devices (including keyboards) that are already supported by high-level APIs.
I've started a topic at the WICG incubator: https://discourse.wicg.io/t/identify-which-of-multiple-keyboards-an-event-came-from/3416

Control key in web browser on Mac

I don't have a Mac, but I have seen its keyboard on pictures and there is a Control key. However the strange thing to me is that on most keyboards shortcuts, system/command key is used instead. Does the Control key on Mac behaves in exactly the same way as Ctrl key on Linux/Windows (in web browsers). To be more specifc, does it keyCode === 17 and does event.ctrlKey work for it?
I just want to implement Ctrl shortcuts for my web application and I'm wondering whether they will work on Macs.
Yes, the keyCode for the Ctrl key is the same on Mac and PC (17).
The keyCode for the command key is 91.
From a usability point of view, Mac's user are not very used to use the Ctrl key since all the common shortcuts use the command key instead. So it would be good if your application support both.

OS Detection in javascript for all the devices and cross-browser

I am working on web analytics, I have to find out the os of the visitor specific with following conditions
1.Cross-browser compatibility.
2.For all devices(tablet,iphone,mobile,deskstop,etc).
3.Maximum possible accuracy.
I have referred some questions regarding os detection, Answer is navigator.platform but it does not supported for some devices
Note: we cannot rely on useragent as well.
Any suggestion will be greatful.
In case it could be PHP instead of JavaScript; this piece of code is so reliable and accurate and have been tested on many devices -mobile devices- and it works like charm:
preg_match("/(android|avantgo|blackberry|nokia|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
this only detects mobile devices but you can tweak the code in different way to get what you need.
Also check this link >> php to detect browser and operating system - which contains PHP codes too.

Capture undo, redo and other key events on different Operating systems in Javascript

Is there any library which can capture key events on any operating system and call the handler based on what action was performed?
For example, undo on Windows in cntrl+z, but on mac it is appleKey/commandkey + z.
So my question is is there any library that can call my undo handler on Windows as well as Mac?
Mousetrap seems like a pretty good start point. From there, you can detect the Apple key ('command') and different sequences and make your own custom aliases. Shouldn't be too difficult. :-)
http://craig.is/killing/mice

Can I use NSSpeechSynthesizer from JavaScript?

I have a short and simple question: Can I use NSSpeechSynthesizer or Mac OS's Text-to-Speech engine from JavaScript (if I'm on a Mac using Safari)? And if so: how?
Thanks!
Johannes
there isn't a way without plugins
A java applet may be able to, but it would likely have to ask the user for permission first.

Categories

Resources