ultralight-ux / Ultralight

Lightweight, high-performance HTML renderer for game and app developers.
https://ultralig.ht
4.69k stars 196 forks source link

JavaScript Alt key detection does not work #488

Open JohnKlenk opened 1 year ago

JohnKlenk commented 1 year ago

Detection of Ctrl and Shift for key/mouse events work, but not Alt detection.

Here's example code you can load in the browser sample app:

<html>
<head><title>Ctrl/Alt/Shift detection test</title></head>
<body>
Click while holding Ctrl or Alt or Shift...<p>
<div id="test"></div>
<script>
  function HandleClick(event)
  {
    let curtime = new Date().toLocaleTimeString();
    if (event.ctrlKey) document.getElementById('test').textContent = Ctrl+click at ${curtime};
    else if (event.altKey) document.getElementById('test').textContent = Alt+click at ${curtime};
    else if (event.shiftKey) document.getElementById('test').textContent = Shift+click at ${curtime};
  }
  document.addEventListener('click', HandleClick);
</script>
</body>
</html>