{"id":297715,"date":"2020-01-26T21:00:13","date_gmt":"2020-01-26T21:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=297715"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=297715","title":{"rendered":"\u0421\u0435\u0440\u0444\u0438\u043d\u0433 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u0433\u0435\u0439\u043c\u043f\u0430\u0434\u043e\u043c (Javascript)"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/485562\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ep\/vg\/pu\/epvgpuyawysxaiqnq7p0vkfv_9y.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u0421\u0438\u0434\u044f \u0437\u0430 \u0441\u0442\u043e\u043b\u043e\u043c, \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043c\u044b\u0448\u043a\u0443 \u0438 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0443, \u0441\u0438\u0434\u044f \u043d\u0430 \u0434\u0438\u0432\u0430\u043d\u0435 \u2014 \u0441\u043a\u043e\u0440\u0435\u0439 \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u0447\u043f\u0430\u0434 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0430 \u0438\u043b\u0438 \u0442\u0430\u0447\u0441\u043a\u0440\u0438\u043d \u043f\u043b\u0430\u043d\u0448\u0435\u0442\u0430. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u0434\u0430\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Leap Motion \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043e\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0436\u0435\u0441\u0442\u043e\u0432. \u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u043f\u043e\u043d\u044f\u043b\u0438, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u0435\u0440\u0444\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0430\u0448\u0438\u043c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043e\u043c. \u0413\u0435\u0439\u043c\u043f\u0430\u0434 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0434\u0435\u043b\u044e\u0441\u044c \u0441 \u0432\u0430\u043c\u0438 \u043a\u0430\u043a:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0433\u0435\u0439\u043c\u043f\u0430\u0434 \u043a \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443<\/li>\n<li>\u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0433\u0435\u0439\u043c\u043f\u0430\u0434\u0430<\/li>\n<li>\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u043a\u0443\u0441 \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0433\u0435\u0439\u043c\u043f\u0430\u0434<\/li>\n<li>\u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0438\u0434\u0431\u0435\u043a \u0432 \u0432\u0438\u0434\u0435 \u0432\u0438\u0431\u0440\u0430\u0446\u0438\u0438<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0439\u0442\u0435 \u0441\u0432\u043e\u0439 \u0433\u0435\u0439\u043c\u043f\u0430\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f USB \u0438\u043b\u0438 Bluetooth \u0438 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h3 id=\"geympad-api\">\u0413\u0435\u0439\u043c\u043f\u0430\u0434 API<\/h3>\n<p>  <\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Gamepad_API\">\u0413\u0435\u0439\u043c\u043f\u0430\u0434 API<\/a> \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 HTML 5. API \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u0435\u0439\u043c\u043f\u0430\u0434\u044b \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435. \u0412 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0441  \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c, \u044d\u0442\u043e API \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u0433\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0433\u0435\u0439\u043c\u043f\u0430\u0434. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0438\u0433\u0440\u0430\u0442\u044c \u0432 \u0438\u0433\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0433\u0435\u0439\u043c\u043f\u0430\u0434 \u043f\u0440\u044f\u043c\u043e \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435, \u0447\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0443\u0442\u043e. \u041d\u043e API \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0438\u0433\u0440. \u041d\u0438\u043a\u0442\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0432\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0432\u0432\u043e\u0434\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0433\u0435\u0439\u043c\u043f\u0430\u0434\u0430 \u0434\u043b\u044f \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0446\u0435\u043b\u0435\u0439.  <\/p>\n<blockquote><p><a href=\"https:\/\/dev.caniuse.com\/gamepad\">Gamepad API \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f<\/a>, \u043d\u043e \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u0434\u0438\u0438 \u0434\u0440\u0430\u0444\u0442\u0430. \u041c\u043e\u0436\u0435\u0442, \u0447\u0442\u043e-\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f, \u0443\u0434\u0430\u043b\u0438\u0442\u0441\u044f \u0438\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c.<\/p><\/blockquote>\n<p>  <\/p>\n<h3 id=\"podklyuchaem-geympad\">\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0433\u0435\u0439\u043c\u043f\u0430\u0434<\/h3>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0433\u0435\u0439\u043c\u043f\u0430\u0434 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043a \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f USB \u0438\u043b\u0438 Bluetooth \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0432\u0430 \u0438\u0432\u0435\u043d\u0442\u0430, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">window.addEventListener('gamepadconnected', function(event) {   \/\/ \u0414\u0435\u043b\u0430\u0435\u043c, \u0447\u0442\u043e-\u0442\u043e \u043d\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435   console.log(event) });  window.addEventListener('gamepaddisconnected', function(event) {   \/\/ \u0414\u0435\u043b\u0430\u0435\u043c, \u0447\u0442\u043e-\u0442\u043e \u043d\u0430 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 });<\/code><\/pre>\n<p>  <\/p>\n<p>\u0413\u0435\u0439\u043c\u043f\u0430\u0434 \u043d\u0430\u0447\u043d\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0432\u044b \u043d\u0430\u0436\u043c\u0435\u0442\u0435 \u043a\u043d\u043e\u043f\u043a\u0443 (\u043f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432. \u041b\u044e\u0431\u0443\u044e \u0438\u043b\u0438 Start). \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e security\/privacy \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u043e\u043e\u0431\u0449\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0436\u0430\u0442\u044c \u043a\u043d\u043e\u043f\u043a\u0443 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u044b\u0442\u0438\u044f \u0433\u0435\u0439\u043c\u043f\u0430\u0434\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0435:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/qy\/yh\/dh\/qyyhdhijlimo1vb57vykhhamo1a.png\"><\/p>\n<p>  <\/p>\n<h3 id=\"raskladka-geympada-knopki-i-osi\">\u0420\u0430\u0441\u043a\u043b\u0430\u0434\u043a\u0430 \u0433\u0435\u0439\u043c\u043f\u0430\u0434\u0430: \u043a\u043d\u043e\u043f\u043a\u0438 \u0438 \u043e\u0441\u0438<\/h3>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c, \u0432 \u043b\u043e\u0433\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0435\u0441\u0442\u044c \u043a\u0443\u0447\u0430 \u043a\u043d\u043e\u043f\u043e\u043a (0 \u2014 16) \u0438 \u043e\u0441\u0438 (axes 0 \u2014 3). \u041d\u043e \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u0430\u043c \u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a \u0438\u0437 \u043a\u043d\u043e\u043f\u043e\u043a \u043f\u0440\u044f\u0447\u0435\u0442\u0441\u044f \u0437\u0430 \u043d\u043e\u043c\u0435\u0440\u043e\u043c? \u0413\u0435\u0439\u043c\u043f\u0430\u0434\u044b \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u043a\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0431\u0440\u0435\u043d\u0434\u0430. \u041f\u043e \u044d\u0442\u043e\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0433\u0435\u0439\u043c\u043f\u0430\u0434 Xbox One \u0438 \u0443 \u043d\u0435\u0433\u043e \u0442\u0430\u043a\u0430\u044f \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u043a\u0430:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ha\/hr\/hb\/hahrhbrn2u26e-q6idtlyxbbbgy.png\"><\/p>\n<p>  <\/p>\n<h3 id=\"slushaem-nazhatie-klavishi\">\u0421\u043b\u0443\u0448\u0430\u0435\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043a\u043b\u0430\u0432\u0438\u0448\u0438<\/h3>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>.addEventListener()<\/code> \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430 \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043a\u043b\u0430\u0432\u0438\u0448\u0438. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u043d\u043e\u043f\u043a\u0438 \u043d\u0430 \u0433\u0435\u0439\u043c\u043f\u0430\u0434\u0435 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0418 \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043f\u043e \u043b\u043e\u0433\u0443 \u0432\u044b\u0448\u0435, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043f\u043e\u043b\u0435 <code>pressed<\/code> \u0432 \u0440\u0443\u0447\u043d\u0443\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const xBoxButtonB = gamepad.buttons[1] if (xBoxButtonB.pressed) {   doSomethingOnButtonPress(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e, \u043d\u0430\u0434\u043e \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u0446\u0438\u043a\u043b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>requestAnimationFrame<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const rAF = window.mozRequestAnimationFrame || window.requestAnimationFrame;   window.addEventListener('gamepadconnected', function() {   updateLoop(); });   function updateLoop() {   \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438   rAF(updateLoop); }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"navigaciya-mezhdu-elementami\">\u041d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u0435\u0439\u043c\u043f\u0430\u0434 \u0434\u043b\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043f\u043e \u0432\u0435\u0431 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0443. \u041d\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043a\u043e\u0442\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u0444\u043e\u043a\u0443\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u044b.<br \/>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const focusableElements = document.querySelectorAll(   'button, [href], input, select, textarea, [tabindex]:not([tabindex=&quot;-1&quot;])' );<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"dvigaem-fokus-programmno\">\u0414\u0432\u0438\u0433\u0430\u0435\u043c \u0444\u043e\u043a\u0443\u0441 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u0446\u0438\u043a\u043b\u0435 \u043f\u043e <code>NodeList<\/code> \u0438 \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>element.focus()<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u044b\u0433\u0430\u0442\u044c \u0444\u043e\u043a\u0443\u0441\u043e\u043c \u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442: <\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">let current;  function updateLoop() {   const gamepad = navigator.getGamepads()[0]   const gamepadBumperL = gamepad.buttons[4]   const gamepadBumperR = gamepad.buttons[5]    if (gamepadBumperL.pressed) { prevItem(current) }   if (gamepadBumperR.pressed) { nextItem(current) }    setTimeout(() =&gt; rAF(updateLoop), 100) }  function prevItem(index) {   current = (index - 1) % focusableElements.length   focusableElements[current].focus() }  function nextItem(index) {   current = (index + 1) % focusableElements.length   focusableElements[current].focus() }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>setTimeout<\/code>. \u041e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f <code>requestAnimationFrame<\/code> \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 100 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434. \u0411\u0435\u0437 \u044d\u0442\u043e\u0433\u043e, \u043e\u0434\u043d\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0448\u0443 \u043c\u043e\u0436\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0433\u0435\u0439\u043c\u043f\u0430\u0434\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u0442 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e \u043d\u0430\u043c onClick, \u0430 \u043d\u0430\u0436\u0430\u0442\u044c \u0438 \u043e\u0442\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043b\u0430\u0432\u0438\u0448\u0443 \u0437\u0430 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<p>  <\/p>\n<h3 id=\"klikaem-po-elementam\">\u041a\u043b\u0438\u043a\u0430\u0435\u043c \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c<\/h3>\n<p>  <\/p>\n<p>\u041a\u043b\u0438\u043a\u0430\u0442\u044c \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>click()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">clickItem(index) {   focusableElements[index].click(); }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"dobavlyaem-fidbek-ispolzuya-vibraciyu\">\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0438\u0434\u0431\u0435\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0438\u0431\u0440\u0430\u0446\u0438\u044e<\/h3>\n<p>  <\/p>\n<p>\u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0433\u0435\u0439\u043c\u043f\u0430\u0434\u044b \u0443\u043c\u0435\u044e\u0442 \u0432\u0438\u0431\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u042d\u0442\u0438 \u0432\u0438\u0431\u0440\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0444\u0438\u0434\u0431\u0435\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0432 \u0438\u0433\u0440\u0430\u0445. \u041d\u043e \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0438\u0434\u0431\u0435\u043a \u043e\u0442 \u0432\u0435\u0431 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435.<\/p>\n<p>  <\/p>\n<p>\u0413\u0435\u0439\u043c\u043f\u0430\u0434\u044b \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043e\u0441\u043d\u0430\u0449\u0435\u043d\u044b \u0434\u0432\u0443\u043c\u044f \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043c\u043e\u0442\u043e\u0440\u0430\u043c\u0438, \u043c\u043e\u0449\u043d\u044b\u043c \u0438 \u0441\u043b\u0430\u0431\u044b\u043c:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/iv\/pz\/el\/ivpzel0b1cyoxyujsfqgofbqeve.png\"><\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u0442\u0438\u043c\u0438 \u043c\u043e\u0442\u043e\u0440\u0430\u043c\u0438 \u0438\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>vibrationActuator<\/code>.<br \/>  \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0438\u0431\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>playEffect()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">gamepad.vibrationActuator.playEffect('dual-rumble', {   startDelay: 0, \/\/ Add a delay in milliseconds   duration: 1000, \/\/ Total duration in milliseconds   weakMagnitude: 0.5, \/\/ intensity (0-1) of the small ERM    strongMagnitude: 1 \/\/ intesity (0-1) of the bigger ERM });<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u043e\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u0432\u0438\u0431\u0440\u0430\u0446\u0438\u0438, \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u043c\u0443 \u043c\u043e\u0442\u043e\u0440\u0443 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u0433\u043e\u043d\u0430. \u041f\u043e \u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0445 \u043e\u0442\u043a\u043b\u0438\u043a\u043e\u0432, \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u043c\u043e\u0442\u043e\u0440.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/td\/hq\/5n\/tdhq5nmlxnfoqkeemtj4cf3yrkc.png\"><\/p>\n<p>  <\/p>\n<h3 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0413\u0435\u0439\u043c\u043f\u0430\u0434 API \u0438 \u0442\u043e \u043a\u0430\u043a \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u043d\u0430 <a href=\"https:\/\/github.com\/voorhoede\/demo-navigate-with-gamepad\">GitHub<\/a> \u0438 \u0434\u0435\u043c\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/demo-navigate-with-gamepad.netlify.com\/\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <\/p>\n<h3 id=\"poleznye-ssylki\">\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h3>\n<p>  <\/p>\n<p><a href=\"https:\/\/html5gamepad.com\/\">html5gamepad.com<\/a> \u2014 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0433\u0435\u0439\u043c\u043f\u0430\u0434\u0430<br \/>  <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Gamepad_API\">Gamepad API on MDN<\/a><\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/485562\/\"> https:\/\/habr.com\/ru\/post\/485562\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/485562\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ep\/vg\/pu\/epvgpuyawysxaiqnq7p0vkfv_9y.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u0421\u0438\u0434\u044f \u0437\u0430 \u0441\u0442\u043e\u043b\u043e\u043c, \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043c\u044b\u0448\u043a\u0443 \u0438 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0443, \u0441\u0438\u0434\u044f \u043d\u0430 \u0434\u0438\u0432\u0430\u043d\u0435 \u2014 \u0441\u043a\u043e\u0440\u0435\u0439 \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u0447\u043f\u0430\u0434 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0430 \u0438\u043b\u0438 \u0442\u0430\u0447\u0441\u043a\u0440\u0438\u043d \u043f\u043b\u0430\u043d\u0448\u0435\u0442\u0430. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u0434\u0430\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Leap Motion \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043e\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0436\u0435\u0441\u0442\u043e\u0432. \u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u043f\u043e\u043d\u044f\u043b\u0438, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u0435\u0440\u0444\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0430\u0448\u0438\u043c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043e\u043c. \u0413\u0435\u0439\u043c\u043f\u0430\u0434 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0434\u0435\u043b\u044e\u0441\u044c \u0441 \u0432\u0430\u043c\u0438 \u043a\u0430\u043a:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0433\u0435\u0439\u043c\u043f\u0430\u0434 \u043a \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443<\/li>\n<li>\u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0433\u0435\u0439\u043c\u043f\u0430\u0434\u0430<\/li>\n<li>\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u043a\u0443\u0441 \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0433\u0435\u0439\u043c\u043f\u0430\u0434<\/li>\n<li>\u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0438\u0434\u0431\u0435\u043a \u0432 \u0432\u0438\u0434\u0435 \u0432\u0438\u0431\u0440\u0430\u0446\u0438\u0438<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0439\u0442\u0435 \u0441\u0432\u043e\u0439 \u0433\u0435\u0439\u043c\u043f\u0430\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f USB \u0438\u043b\u0438 Bluetooth \u0438 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-297715","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297715"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297715\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}